diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7565418..aaf8f0b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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.*' @@ -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 diff --git a/composer.json b/composer.json index 830303a..d5bc181 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 864b650..373e04b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 diff --git a/src/Doctrine/ORM/GeocoderListener.php b/src/Doctrine/ORM/GeocoderListener.php index 070d3a8..ef3a594 100644 --- a/src/Doctrine/ORM/GeocoderListener.php +++ b/src/Doctrine/ORM/GeocoderListener.php @@ -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) { diff --git a/src/Mapping/Driver/AnnotationDriver.php b/src/Mapping/Driver/AnnotationDriver.php index e2ae849..7108990 100644 --- a/src/Mapping/Driver/AnnotationDriver.php +++ b/src/Mapping/Driver/AnnotationDriver.php @@ -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 @@ -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))); @@ -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)); + } } diff --git a/src/Mapping/Driver/AttributeDriver.php b/src/Mapping/Driver/AttributeDriver.php index 2b1cbaa..703b0ef 100644 --- a/src/Mapping/Driver/AttributeDriver.php +++ b/src/Mapping/Driver/AttributeDriver.php @@ -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 @@ -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; } @@ -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); @@ -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)); + } }