Skip to content

Commit

Permalink
Support Doctrine ORM v3
Browse files Browse the repository at this point in the history
  • Loading branch information
norkunas committed Oct 3, 2024
1 parent 0e1b7eb commit 0509194
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
matrix:
dependencies: ['highest']
php: [ '7.4', '8.0', '8.1', '8.2' ]
sf_version: [ '4.4.*', '5.4.*', '6.4.*', '7.0.*' ]
sf_version: [ '4.4.*', '5.4.*', '6.4.*', '7.1.*' ]
# include:
# - php: '7.4'
# sf_version: '4.4.*'
Expand All @@ -79,11 +79,11 @@ jobs:
- php: '8.0'
sf_version: '6.4.*'
- php: '7.4'
sf_version: '7.0.*'
sf_version: '7.1.*'
- php: '8.0'
sf_version: '7.0.*'
sf_version: '7.1.*'
- php: '8.1'
sf_version: '7.0.*'
sf_version: '7.1.*'
steps:
- name: "Checkout code"
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"require-dev": {
"doctrine/annotations": "^1.11.1 || ^2.0",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/orm": "^2.8",
"doctrine/orm": "^2.8 || ^3.0",
"fakerphp/faker": "^1.20",
"friendsofphp/php-cs-fixer": "^3.0",
"geocoder-php/algolia-places-provider": "^0.4",
Expand Down
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ parameters:
count: 1
path: src/Doctrine/ORM/GeocoderListener.php

-
message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AnnotationDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
count: 1
path: src/Mapping/Driver/AnnotationDriver.php

-
message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AttributeDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
count: 1
path: src/Mapping/Driver/AttributeDriver.php

-
message: "#^Parameter \\#1 \\$text of method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:withText\\(\\) expects string, string\\|null given\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/Doctrine/ORM/GeocoderListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function getSubscribedEvents(): array
*/
public function onFlush(OnFlushEventArgs $args)
{
$em = method_exists($args, 'getObjectManager') ? $args->getObjectManager() : $args->getEntityManager();
$em = method_exists($args, 'getEntityManager') ? $args->getEntityManager() : $args->getObjectManager();
$uow = $em->getUnitOfWork();

foreach ($uow->getScheduledEntityInsertions() as $entity) {
Expand Down
14 changes: 12 additions & 2 deletions src/Mapping/Driver/AnnotationDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Bazinga\GeocoderBundle\Mapping\Exception;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;

/**
* @author Markus Bachmann <[email protected]>
Expand All @@ -32,14 +33,14 @@ public function __construct(Reader $reader)

public function isGeocodeable($object): bool
{
$reflection = ClassUtils::newReflectionObject($object);
$reflection = self::getReflection($object);

return (bool) $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class);
}

public function loadMetadataFromObject($object)
{
$reflection = ClassUtils::newReflectionObject($object);
$reflection = self::getReflection($object);

if (!$annotation = $this->reader->getClassAnnotation($reflection, Annotations\Geocodeable::class)) {
throw new Exception\MappingException(sprintf('The class %s is not geocodeable', get_class($object)));
Expand Down Expand Up @@ -74,4 +75,13 @@ public function loadMetadataFromObject($object)

return $metadata;
}

private static function getReflection(object $object): \ReflectionClass
{
if (class_exists(ClassUtils::class)) {
return ClassUtils::newReflectionObject($object);
}

return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object));
}
}
14 changes: 12 additions & 2 deletions src/Mapping/Driver/AttributeDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Bazinga\GeocoderBundle\Mapping\ClassMetadata;
use Bazinga\GeocoderBundle\Mapping\Exception\MappingException;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;

/**
* @author Pierre du Plessis <[email protected]>
Expand All @@ -28,7 +29,7 @@ public function isGeocodeable($object): bool
return false;
}

$reflection = ClassUtils::newReflectionObject($object);
$reflection = self::getReflection($object);

return count($reflection->getAttributes(Annotations\Geocodeable::class)) > 0;
}
Expand All @@ -42,7 +43,7 @@ public function loadMetadataFromObject($object): ClassMetadata
throw new MappingException(sprintf('The class %s is not geocodeable', get_class($object)));
}

$reflection = ClassUtils::newReflectionObject($object);
$reflection = self::getReflection($object);

$attributes = $reflection->getAttributes(Annotations\Geocodeable::class);

Expand Down Expand Up @@ -79,4 +80,13 @@ public function loadMetadataFromObject($object): ClassMetadata

return $metadata;
}

private static function getReflection(object $object): \ReflectionClass
{
if (class_exists(ClassUtils::class)) {
return ClassUtils::newReflectionObject($object);
}

return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object));
}
}

0 comments on commit 0509194

Please sign in to comment.