Skip to content

Commit f3373e5

Browse files
committed
Support Doctrine ORM v3
1 parent 0e1b7eb commit f3373e5

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

Diff for: .github/workflows/ci.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ jobs:
6363
matrix:
6464
dependencies: ['highest']
6565
php: [ '7.4', '8.0', '8.1', '8.2' ]
66-
sf_version: [ '4.4.*', '5.4.*', '6.4.*', '7.0.*' ]
66+
sf_version: [ '4.4.*', '5.4.*', '6.4.*', '7.1.*' ]
6767
# include:
6868
# - php: '7.4'
6969
# sf_version: '4.4.*'
@@ -79,11 +79,11 @@ jobs:
7979
- php: '8.0'
8080
sf_version: '6.4.*'
8181
- php: '7.4'
82-
sf_version: '7.0.*'
82+
sf_version: '7.1.*'
8383
- php: '8.0'
84-
sf_version: '7.0.*'
84+
sf_version: '7.1.*'
8585
- php: '8.1'
86-
sf_version: '7.0.*'
86+
sf_version: '7.1.*'
8787
steps:
8888
- name: "Checkout code"
8989
uses: actions/checkout@v4

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"require-dev": {
2727
"doctrine/annotations": "^1.11.1 || ^2.0",
2828
"doctrine/doctrine-bundle": "^2.3",
29-
"doctrine/orm": "^2.8",
29+
"doctrine/orm": "^2.8 || ^3.0",
3030
"fakerphp/faker": "^1.20",
3131
"friendsofphp/php-cs-fixer": "^3.0",
3232
"geocoder-php/algolia-places-provider": "^0.4",

Diff for: phpstan-baseline.neon

+15
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ parameters:
125125
count: 1
126126
path: src/DependencyInjection/Configuration.php
127127

128+
-
129+
message: "#^Call to an undefined method Doctrine\\\\ORM\\\\Event\\\\OnFlushEventArgs\\:\\:getEntityManager\\(\\)\\.$#"
130+
count: 1
131+
path: src/Doctrine/ORM/GeocoderListener.php
132+
128133
-
129134
message: "#^Cannot call method getLatitude\\(\\) on Geocoder\\\\Model\\\\Coordinates\\|null\\.$#"
130135
count: 1
@@ -135,6 +140,16 @@ parameters:
135140
count: 1
136141
path: src/Doctrine/ORM/GeocoderListener.php
137142

143+
-
144+
message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AnnotationDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
145+
count: 1
146+
path: src/Mapping/Driver/AnnotationDriver.php
147+
148+
-
149+
message: "#^Method Bazinga\\\\GeocoderBundle\\\\Mapping\\\\Driver\\\\AttributeDriver\\:\\:getReflection\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
150+
count: 1
151+
path: src/Mapping/Driver/AttributeDriver.php
152+
138153
-
139154
message: "#^Parameter \\#1 \\$text of method Geocoder\\\\Query\\\\GeocodeQuery\\:\\:withText\\(\\) expects string, string\\|null given\\.$#"
140155
count: 1

Diff for: src/Mapping/Driver/AnnotationDriver.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Bazinga\GeocoderBundle\Mapping\Exception;
1818
use Doctrine\Common\Annotations\Reader;
1919
use Doctrine\Common\Util\ClassUtils;
20+
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
2021

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

3334
public function isGeocodeable($object): bool
3435
{
35-
$reflection = ClassUtils::newReflectionObject($object);
36+
$reflection = self::getReflection($object);
3637

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

4041
public function loadMetadataFromObject($object)
4142
{
42-
$reflection = ClassUtils::newReflectionObject($object);
43+
$reflection = self::getReflection($object);
4344

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

7576
return $metadata;
7677
}
78+
79+
private static function getReflection(object $object): \ReflectionClass
80+
{
81+
if (class_exists(ClassUtils::class)) {
82+
return ClassUtils::newReflectionObject($object);
83+
}
84+
85+
return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object));
86+
}
7787
}

Diff for: src/Mapping/Driver/AttributeDriver.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Bazinga\GeocoderBundle\Mapping\ClassMetadata;
1717
use Bazinga\GeocoderBundle\Mapping\Exception\MappingException;
1818
use Doctrine\Common\Util\ClassUtils;
19+
use Doctrine\ORM\Proxy\DefaultProxyClassNameResolver;
1920

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

31-
$reflection = ClassUtils::newReflectionObject($object);
32+
$reflection = self::getReflection($object);
3233

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

45-
$reflection = ClassUtils::newReflectionObject($object);
46+
$reflection = self::getReflection($object);
4647

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

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

8081
return $metadata;
8182
}
83+
84+
private static function getReflection(object $object): \ReflectionClass
85+
{
86+
if (class_exists(ClassUtils::class)) {
87+
return ClassUtils::newReflectionObject($object);
88+
}
89+
90+
return new \ReflectionClass(DefaultProxyClassNameResolver::getClass($object));
91+
}
8292
}

0 commit comments

Comments
 (0)