Skip to content

Commit

Permalink
Merge pull request #356 from norkunas/orm
Browse files Browse the repository at this point in the history
Support Doctrine ORM v3
  • Loading branch information
norkunas authored Oct 3, 2024
2 parents 0e1b7eb + f3373e5 commit 3904397
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 9 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
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ parameters:
count: 1
path: src/DependencyInjection/Configuration.php

-
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#"
count: 1
path: src/Doctrine/ORM/GeocoderListener.php

-
message: "#^Cannot call method getLatitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#"
count: 1
Expand All @@ -135,6 +140,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
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 <markus.bachmann@bachi.biz>
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 <pdples@gmail.com>
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 3904397

Please sign in to comment.