Skip to content

Commit dd564de

Browse files
authored
[4.4] handle legacy Doctrine Persistance AnnotationDriver (#1181)
1 parent 8e8968a commit dd564de

13 files changed

+66
-120
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ jobs:
4242

4343
-
4444
name: "Composer install"
45-
uses: "ramsey/composer-install@v1"
45+
uses: "ramsey/composer-install@v2"
4646
with:
4747
composer-options: "--no-scripts"
4848

4949
-
5050
name: "Composer install php-cs-fixer"
51-
uses: "ramsey/composer-install@v1"
51+
uses: "ramsey/composer-install@v2"
5252
with:
5353
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
5454

@@ -90,12 +90,9 @@ jobs:
9090
fail-fast: false
9191
matrix:
9292
php-version:
93-
- '8.0'
93+
- '7.4'
9494
symfony-version:
9595
- '4.4.*'
96-
- '5.3.*'
97-
- '5.4.x-dev'
98-
- '6.0.x-dev'
9996
dependency-versions: ['highest']
10097
allow-dev-deps-in-apps: ['0']
10198
include:
@@ -106,11 +103,11 @@ jobs:
106103
dependency-versions: 'highest'
107104
# testing lowest php version with highest 5.x stable
108105
- php-version: '7.2.5'
109-
symfony-version: '5.3.*'
106+
symfony-version: '4.4.*'
110107
dependency-versions: 'lowest'
111108
# testing bleeding edge PHP with highest 5.x stable
112-
- php-version: '8.1'
113-
symfony-version: '5.3.*'
109+
- php-version: '7.4'
110+
symfony-version: '4.4.*'
114111
dependency-versions: 'highest'
115112
# temporarily needed until some packages support php 8.1
116113
allow-dev-deps-in-apps: '1'
@@ -141,23 +138,30 @@ jobs:
141138
- name: "Add PHPUnit matcher"
142139
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
143140

141+
- name: "Allow flex globally"
142+
run: composer global config --no-plugins allow-plugins.symfony/flex true
143+
144144
- name: "Require symfony/flex"
145145
run: composer global require --no-progress --no-scripts --no-plugins symfony/flex
146146

147+
- name: "Composer Validate"
148+
run: composer validate -vvv
149+
147150
- name: "Composer install"
148-
uses: "ramsey/composer-install@v1"
151+
uses: "ramsey/composer-install@v2"
149152
with:
150153
dependency-versions: "${{ matrix.dependency-versions }}"
154+
composer-options: "-vvv"
151155

152156
- name: "Composer install php-cs-fixer"
153-
uses: "ramsey/composer-install@v1"
157+
uses: "ramsey/composer-install@v2"
154158
with:
155-
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer"
159+
composer-options: "--no-scripts --working-dir=tools/php-cs-fixer -vvv"
156160

157161
- name: "Composer install twigcs"
158-
uses: "ramsey/composer-install@v1"
162+
uses: "ramsey/composer-install@v2"
159163
with:
160-
composer-options: "--no-scripts --working-dir=tools/twigcs"
164+
composer-options: "--no-scripts --working-dir=tools/twigcs -vvv"
161165

162166
- name: "Install PHPUnit"
163167
run: vendor/bin/simple-phpunit install

appveyor.yml

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/Doctrine/DoctrineHelper.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
use Doctrine\Common\Persistence\Mapping\MappingException as LegacyPersistenceMappingException;
1717
use Doctrine\DBAL\Connection;
1818
use Doctrine\ORM\EntityManagerInterface;
19+
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
1920
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
2021
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
2122
use Doctrine\ORM\Mapping\NamingStrategy;
2223
use Doctrine\ORM\Tools\DisconnectedClassMetadataFactory;
2324
use Doctrine\Persistence\ManagerRegistry;
2425
use Doctrine\Persistence\Mapping\AbstractClassMetadataFactory;
2526
use Doctrine\Persistence\Mapping\ClassMetadata;
26-
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver;
27+
use Doctrine\Persistence\Mapping\Driver\AnnotationDriver as LegacyAnnotationDriver;
2728
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
2829
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain;
2930
use Doctrine\Persistence\Mapping\MappingException as PersistenceMappingException;
@@ -141,7 +142,7 @@ public function doesClassUseDriver(string $className, string $driverClass): bool
141142

142143
public function isClassAnnotated(string $className): bool
143144
{
144-
return $this->doesClassUseDriver($className, AnnotationDriver::class);
145+
return $this->doesClassUseDriver($className, $this->getAnnotationDriver());
145146
}
146147

147148
public function doesClassUsesAttributes(string $className): bool
@@ -177,7 +178,7 @@ public function getEntitiesForAutocomplete(): array
177178
*/
178179
public function getMetadata(string $classOrNamespace = null, bool $disconnected = false)
179180
{
180-
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
181+
$classNames = (new \ReflectionClass($this->getAnnotationDriver()))->getProperty('classNames');
181182
$classNames->setAccessible(true);
182183

183184
// Invalidating the cached AnnotationDriver::$classNames to find new Entity classes
@@ -186,8 +187,8 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
186187
if (null === $annotationDriver) {
187188
continue;
188189
}
189-
if (class_exists(AnnotationDriver::class)) {
190-
$classNames = (new \ReflectionClass(AnnotationDriver::class))->getProperty('classNames');
190+
if (class_exists($this->getAnnotationDriver())) {
191+
$classNames = (new \ReflectionClass($this->getAnnotationDriver()))->getProperty('classNames');
191192
}
192193
if ($annotationDriver instanceof AttributeDriver) {
193194
$classNames = (new \ReflectionClass(AttributeDriver::class))->getProperty('classNames');
@@ -229,7 +230,7 @@ public function getMetadata(string $classOrNamespace = null, bool $disconnected
229230
$metadataDriver = $em->getConfiguration()->getMetadataDriverImpl();
230231
if ($this->isInstanceOf($metadataDriver, MappingDriverChain::class)) {
231232
foreach ($metadataDriver->getDrivers() as $driver) {
232-
if ($this->isInstanceOf($driver, AnnotationDriver::class)) {
233+
if ($this->isInstanceOf($driver, $this->getAnnotationDriver())) {
233234
$classNames->setValue($driver, null);
234235
}
235236
}
@@ -334,4 +335,16 @@ private function getMappingDriverForNamespace(string $namespace): ?MappingDriver
334335

335336
return $foundDriver;
336337
}
338+
339+
/**
340+
* Only needed in 1.39.x releases - AnnotationDriver was moved from Doctrine Persistence -> ORM.
341+
*/
342+
private function getAnnotationDriver(): string
343+
{
344+
if (class_exists(AnnotationDriver::class)) {
345+
return AnnotationDriver::class;
346+
}
347+
348+
return LegacyAnnotationDriver::class;
349+
}
337350
}

src/Maker/MakeResetPassword.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
* @author Antoine Michelet <[email protected]>
6666
*
6767
* @internal
68+
*
6869
* @final
6970
*/
7071
class MakeResetPassword extends AbstractMaker

src/Maker/MakeUser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function generate(InputInterface $input, ConsoleStyle $io, Generator $gen
164164
// need to write changes early so we can modify the contents below
165165
$generator->writeChanges();
166166

167-
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && ($this->doctrineHelper->isDoctrineSupportingAttributes()) && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
167+
$useAttributesForDoctrineMapping = $userClassConfiguration->isEntity() && $this->doctrineHelper->isDoctrineSupportingAttributes() && $this->doctrineHelper->doesClassUsesAttributes($userClassNameDetails->getFullName());
168168

169169
// B) Implement UserInterface
170170
$manipulator = new ClassSourceManipulator(

src/Test/MakerTestRunner.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,11 @@ public function removeFromFile(string $filename, string $find, bool $allowNotFou
170170

171171
public function configureDatabase(bool $createSchema = true): void
172172
{
173-
// @legacy Drop conditional when Symfony 4.4 is no longer supported.
174-
if (50000 > $this->environment->getSymfonyVersionInApp()) {
175-
$this->replaceInFile(
176-
'.env',
177-
'postgresql://db_user:[email protected]:5432/db_name?serverVersion=13&charset=utf8',
178-
getenv('TEST_DATABASE_DSN')
179-
);
180-
} else {
181-
$this->replaceInFile(
182-
'.env',
183-
'postgresql://symfony:[email protected]:5432/app?serverVersion=13&charset=utf8',
184-
getenv('TEST_DATABASE_DSN')
185-
);
186-
}
173+
$this->replaceInFile(
174+
'.env',
175+
'postgresql://app:[email protected]:5432/app?serverVersion=14&charset=utf8',
176+
getenv('TEST_DATABASE_DSN')
177+
);
187178

188179
// Flex includes a recipe to suffix the dbname w/ "_test" - lets keep
189180
// things simple for these tests and not do that.

src/Util/ComposeFileManipulator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @author Jesse Rushlow <[email protected]>
2121
*
2222
* @internal
23+
*
2324
* @final
2425
*/
2526
class ComposeFileManipulator

src/Util/YamlSourceManipulator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ private function changeValueInYaml($value)
479479
// this means we need to break onto the next line
480480

481481
// increase(override) the indentation
482-
$newYamlValue = "\n".$this->indentMultilineYamlArray($newYamlValue, ($this->indentationForDepths[$this->depth] + $this->getPreferredIndentationSize()));
482+
$newYamlValue = "\n".$this->indentMultilineYamlArray($newYamlValue, $this->indentationForDepths[$this->depth] + $this->getPreferredIndentationSize());
483483
} elseif ($this->isCurrentArrayMultiline() && $this->isCurrentArraySequence()) {
484484
// we are a multi-line sequence, so drop to next line, indent and add "- " in front
485485
$newYamlValue = "\n".$this->indentMultilineYamlArray('- '.$newYamlValue);
@@ -628,7 +628,7 @@ private function getEndOfPreviousKeyPosition($key): int
628628
}
629629

630630
// find either a line break or a , that is the end of the previous key
631-
while (\in_array(($char = substr($this->contents, $startOfKey - 1, 1)), [',', "\n"])) {
631+
while (\in_array($char = substr($this->contents, $startOfKey - 1, 1), [',', "\n"])) {
632632
--$startOfKey;
633633
}
634634

tests/Maker/MakeMessengerMiddlewareTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function getTestDetails()
2727
yield 'it_generates_messenger_middleware' => [$this->createMakerTest()
2828
->run(function (MakerTestRunner $runner) {
2929
$runner->runMaker(
30-
[
31-
// middleware name
32-
'CustomMiddleware',
33-
]);
30+
[
31+
// middleware name
32+
'CustomMiddleware',
33+
]);
3434

3535
$this->assertFileExists($runner->getPath('src/Middleware/CustomMiddleware.php'));
3636
}),

tests/Security/SecurityControllerBuilderTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testLoginMethod(): void
2929
sprintf('%s/legacy_add_login_method/%s', $this->expectedBasePath, 'SecurityController_login.php')
3030
);
3131

32-
if ((\PHP_VERSION_ID >= 80000)) {
32+
if (\PHP_VERSION_ID >= 80000) {
3333
$this->runMethodTest(
3434
'addLoginMethod',
3535
false,
@@ -47,7 +47,7 @@ public function testLogoutMethod(): void
4747
sprintf('%s/legacy_add_logout_method/%s', $this->expectedBasePath, 'SecurityController_logout.php')
4848
);
4949

50-
if ((\PHP_VERSION_ID >= 80000)) {
50+
if (\PHP_VERSION_ID >= 80000) {
5151
$this->runMethodTest(
5252
'addLogoutMethod',
5353
false,
@@ -70,7 +70,7 @@ public function testLoginAndLogoutMethod(): void
7070
$csm->getSourceCode()
7171
);
7272

73-
if ((\PHP_VERSION_ID >= 80000)) {
73+
if (\PHP_VERSION_ID >= 80000) {
7474
$builder = $this->getSecurityControllerBuilder(false);
7575
$csm = $this->getClassSourceManipulator();
7676

0 commit comments

Comments
 (0)