Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Doctrine/ORM/GeocodeEntityListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ private function geocodeEntity(ClassMetadata $metadata, object $entity): void
$result = $results->first();
$metadata->latitudeProperty?->setValue($entity, $result->getCoordinates()->getLatitude());
$metadata->longitudeProperty?->setValue($entity, $result->getCoordinates()->getLongitude());
$metadata->northProperty?->setValue($entity, $result->getBounds()?->getNorth());
$metadata->southProperty?->setValue($entity, $result->getBounds()?->getSouth());
$metadata->eastProperty?->setValue($entity, $result->getBounds()?->getEast());
$metadata->westProperty?->setValue($entity, $result->getBounds()?->getWest());
$metadata->streetNumberProperty?->setValue($entity, $result->getStreetNumber());
$metadata->streetNameProperty?->setValue($entity, $result->getStreetName());
$metadata->localityProperty?->setValue($entity, $result->getLocality());
$metadata->postalCodeProperty?->setValue($entity, $result->getPostalCode());
$metadata->subLocalityProperty?->setValue($entity, $result->getSubLocality());
$metadata->countryProperty?->setValue($entity, $result->getCountry());
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/Country.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Country
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/East.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class East
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/Locality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class Locality
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/North.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class North
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/PostalCode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class PostalCode
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/South.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class South
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/StreetName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class StreetName
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/StreetNumber.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class StreetNumber
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/SubLocality.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class SubLocality
{
}
16 changes: 16 additions & 0 deletions src/Mapping/Attributes/West.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file is part of the BazingaGeocoderBundle package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Bazinga\GeocoderBundle\Mapping\Attributes;

#[\Attribute(\Attribute::TARGET_PROPERTY)]
class West
{
}
10 changes: 10 additions & 0 deletions src/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public function __construct(
public readonly ?\ReflectionProperty $latitudeProperty = null,
public readonly ?\ReflectionProperty $longitudeProperty = null,
public readonly ?\ReflectionMethod $addressGetter = null,
public readonly ?\ReflectionProperty $northProperty = null,
public readonly ?\ReflectionProperty $southProperty = null,
public readonly ?\ReflectionProperty $eastProperty = null,
public readonly ?\ReflectionProperty $westProperty = null,
public readonly ?\ReflectionProperty $streetNumberProperty = null,
public readonly ?\ReflectionProperty $streetNameProperty = null,
public readonly ?\ReflectionProperty $localityProperty = null,
public readonly ?\ReflectionProperty $postalCodeProperty = null,
public readonly ?\ReflectionProperty $subLocalityProperty = null,
public readonly ?\ReflectionProperty $countryProperty = null,
) {
}
}
24 changes: 18 additions & 6 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,22 @@
*/
final class AttributeDriver implements DriverInterface
{
private const PROPERTY_MATRIX = [
Attributes\Latitude::class => 'latitudeProperty',
Attributes\Longitude::class => 'longitudeProperty',
Attributes\Address::class => 'addressProperty',
Attributes\North::class => 'northProperty',
Attributes\South::class => 'southProperty',
Attributes\East::class => 'eastProperty',
Attributes\West::class => 'westProperty',
Attributes\StreetNumber::class => 'streetNumberProperty',
Attributes\StreetName::class => 'streetNameProperty',
Attributes\Locality::class => 'localityProperty',
Attributes\PostalCode::class => 'postalCodeProperty',
Attributes\SubLocality::class => 'subLocalityProperty',
Attributes\Country::class => 'countryProperty',
];

public function isGeocodeable(object $object): bool
{
$reflection = self::getReflection($object);
Expand All @@ -47,12 +63,8 @@

foreach ($reflection->getProperties() as $property) {
foreach ($property->getAttributes() as $attribute) {
if (Attributes\Latitude::class === $attribute->getName()) {
$args['latitudeProperty'] = $property;
} elseif (Attributes\Longitude::class === $attribute->getName()) {
$args['longitudeProperty'] = $property;
} elseif (Attributes\Address::class === $attribute->getName()) {
$args['addressProperty'] = $property;
if (isset(self::PROPERTY_MATRIX[$attribute->getName()])) {
$args[self::PROPERTY_MATRIX[$attribute->getName()]] = $property;
}
}
}
Expand All @@ -67,7 +79,7 @@
}
}

return new ClassMetadata(...$args);

Check failure on line 82 in src/Mapping/Driver/AttributeDriver.php

View workflow job for this annotation

GitHub Actions / PHPStan

Parameter #1 $provider of class Bazinga\GeocoderBundle\Mapping\ClassMetadata constructor expects non-empty-string, ReflectionMethod|ReflectionProperty|non-empty-string given.
}

/**
Expand Down
50 changes: 50 additions & 0 deletions tests/Functional/Fixtures/Entity/DummyWithProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@
namespace Bazinga\GeocoderBundle\Tests\Functional\Fixtures\Entity;

use Bazinga\GeocoderBundle\Mapping\Attributes\Address;
use Bazinga\GeocoderBundle\Mapping\Attributes\Country;
use Bazinga\GeocoderBundle\Mapping\Attributes\East;
use Bazinga\GeocoderBundle\Mapping\Attributes\Geocodeable;
use Bazinga\GeocoderBundle\Mapping\Attributes\Latitude;
use Bazinga\GeocoderBundle\Mapping\Attributes\Locality;
use Bazinga\GeocoderBundle\Mapping\Attributes\Longitude;
use Bazinga\GeocoderBundle\Mapping\Attributes\North;
use Bazinga\GeocoderBundle\Mapping\Attributes\PostalCode;
use Bazinga\GeocoderBundle\Mapping\Attributes\South;
use Bazinga\GeocoderBundle\Mapping\Attributes\StreetName;
use Bazinga\GeocoderBundle\Mapping\Attributes\StreetNumber;
use Bazinga\GeocoderBundle\Mapping\Attributes\SubLocality;
use Bazinga\GeocoderBundle\Mapping\Attributes\West;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
Expand All @@ -42,4 +52,44 @@ class DummyWithProperty
#[Column(type: Types::STRING)]
#[Address]
public ?string $address = null;

#[Column(type: Types::FLOAT, nullable: true)]
#[North]
public ?float $north = null;

#[Column(type: Types::FLOAT, nullable: true)]
#[South]
public ?float $south = null;

#[Column(type: Types::FLOAT, nullable: true)]
#[East]
public ?float $east = null;

#[Column(type: Types::FLOAT, nullable: true)]
#[West]
public ?float $west = null;

#[Column(type: Types::STRING, nullable: true)]
#[StreetNumber]
public int|string|null $streetNumber = null;

#[Column(type: Types::STRING, nullable: true)]
#[StreetName]
public ?string $streetName = null;

#[Column(type: Types::STRING, nullable: true)]
#[Locality]
public ?string $locality = null;

#[Column(type: Types::STRING, nullable: true)]
#[PostalCode]
public ?string $postalCode = null;

#[Column(type: Types::STRING, nullable: true)]
#[SubLocality]
public ?string $subLocality = null;

#[Column(type: Types::STRING, nullable: true)]
#[Country]
public ?string $country = null;
}
Loading
Loading