From b8d62d85cfa187c8d192a1e1fd1230b73a16741b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Thu, 30 Oct 2025 15:14:15 +0100 Subject: [PATCH 01/10] Deprecate ClassMetadataFactory::setMetadataFor() https://github.com/doctrine/orm/pull/12174 --- docs/en/reference/index.rst | 4 +++- src/Mapping/AbstractClassMetadataFactory.php | 2 +- src/Mapping/ClassMetadataFactory.php | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/index.rst b/docs/en/reference/index.rst index e17eca8f..f9646a6d 100644 --- a/docs/en/reference/index.rst +++ b/docs/en/reference/index.rst @@ -149,10 +149,12 @@ your mapped PHP classes. public function getAllMetadata(); public function getMetadataFor($className); public function hasMetadataFor($className); - public function setMetadataFor($className, $class); + public function setMetadataFor($className, $class); // Deprecated public function isTransient($className); } +The method ``setMetadataFor()`` is deprecated and should not be used. + Mapping Driver ============== diff --git a/src/Mapping/AbstractClassMetadataFactory.php b/src/Mapping/AbstractClassMetadataFactory.php index b2f0573d..575c0f01 100644 --- a/src/Mapping/AbstractClassMetadataFactory.php +++ b/src/Mapping/AbstractClassMetadataFactory.php @@ -232,7 +232,7 @@ public function hasMetadataFor(string $className): bool /** * Sets the metadata descriptor for a specific class. * - * NOTE: This is only useful in very special cases, like when generating proxy classes. + * @deprecated Since 4.2, use a custom ClassMetadataFactory implementation if you need to set metadata manually. * * @phpstan-param class-string $className * @phpstan-param CMTemplate $class diff --git a/src/Mapping/ClassMetadataFactory.php b/src/Mapping/ClassMetadataFactory.php index 68e4595b..6b3c2ae8 100644 --- a/src/Mapping/ClassMetadataFactory.php +++ b/src/Mapping/ClassMetadataFactory.php @@ -41,6 +41,8 @@ public function hasMetadataFor(string $className): bool; /** * Sets the metadata descriptor for a specific class. * + * @deprecated Since 4.2, use a custom ClassMetadataFactory implementation if you need to set metadata manually. + * * @param class-string $className * @phpstan-param T $class */ From 0550eefaf41248e91d3db2fb5a62002026898e24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 29 Oct 2025 17:26:54 +0100 Subject: [PATCH 02/10] Make AbstractManagerRegistry::$proxyInterfaceName nullable --- UPGRADE.md | 5 ++++ src/AbstractManagerRegistry.php | 26 ++++++++-------- tests/ManagerRegistryTest.php | 53 +++++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index ca89d1bc..d3a5078b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -41,6 +41,11 @@ return function (ClassMetadata $metadata): void { }; ``` +## Do not pass any proxy interface to `AbstractManagerRegistry` when using native proxies + +With PHP 8.4 native lazy objects, you don't need to pass any proxy interface to +`AbstractManagerRegistry`. The class of the lazy objects is the class being mapped. + # Upgrade to 4.0 ## BC Break: Removed `StaticReflectionService` diff --git a/src/AbstractManagerRegistry.php b/src/AbstractManagerRegistry.php index 68049cce..351848ba 100644 --- a/src/AbstractManagerRegistry.php +++ b/src/AbstractManagerRegistry.php @@ -18,7 +18,7 @@ abstract class AbstractManagerRegistry implements ManagerRegistry /** * @param array $connections * @param array $managers - * @phpstan-param class-string $proxyInterfaceName + * @phpstan-param class-string|null $proxyInterfaceName Set to null when native lazy objects are used. */ public function __construct( private readonly string $name, @@ -26,7 +26,7 @@ public function __construct( private array $managers, private readonly string $defaultConnection, private readonly string $defaultManager, - private readonly string $proxyInterfaceName, + private readonly string|null $proxyInterfaceName = null, ) { } @@ -127,19 +127,21 @@ public function getManager(string|null $name = null): ObjectManager public function getManagerForClass(string $class): ObjectManager|null { - $proxyClass = new ReflectionClass($class); - if ($proxyClass->isAnonymous()) { - return null; - } - - if ($proxyClass->implementsInterface($this->proxyInterfaceName)) { - $parentClass = $proxyClass->getParentClass(); - - if ($parentClass === false) { + if ($this->proxyInterfaceName !== null) { + $proxyClass = new ReflectionClass($class); + if ($proxyClass->isAnonymous()) { return null; } - $class = $parentClass->getName(); + if ($proxyClass->implementsInterface($this->proxyInterfaceName)) { + $parentClass = $proxyClass->getParentClass(); + + if ($parentClass === false) { + return null; + } + + $class = $parentClass->getName(); + } } foreach ($this->managers as $id) { diff --git a/tests/ManagerRegistryTest.php b/tests/ManagerRegistryTest.php index a32dcc4a..c796d658 100644 --- a/tests/ManagerRegistryTest.php +++ b/tests/ManagerRegistryTest.php @@ -45,6 +45,22 @@ public function testGetManagerForClass(): void ); } + public function testGetManagerForClassAnonymous(): void + { + $anonymousClass = new class extends TestObject implements Proxy { + public function __isInitialized(): bool + { + return true; + } + + public function __load(): void + { + } + }; + + self::assertNull($this->mr->getManagerForClass($anonymousClass::class)); + } + public function testGetManagerForProxiedClass(): void { self::assertInstanceOf( @@ -64,6 +80,39 @@ public function testGetManagerForAnonymousClass(): void })::class)); } + public function testGetManagerForWithoutProxyInterface(): void + { + $mr = new TestManagerRegistry( + 'ORM', + ['default' => 'default_connection'], + ['default' => 'default_manager'], + 'default', + 'default', + null, + $this->getManagerFactory(), + ); + + self::assertInstanceOf( + ObjectManager::class, + $mr->getManagerForClass(TestObject::class), + ); + + self::assertNull($mr->getManagerForClass(TestObjectProxy::class)); + + $anonymousClass = new class extends TestObject implements Proxy { + public function __isInitialized(): bool + { + return true; + } + + public function __load(): void + { + } + }; + + self::assertNull($mr->getManagerForClass($anonymousClass::class)); + } + public function testResetManager(): void { $manager = $this->mr->getManager(); @@ -179,7 +228,7 @@ class TestManagerRegistry extends AbstractManagerRegistry /** * {@inheritDoc} * - * @phpstan-param class-string $proxyInterfaceName + * @phpstan-param class-string|null $proxyInterfaceName */ public function __construct( string $name, @@ -187,7 +236,7 @@ public function __construct( array $managers, string $defaultConnection, string $defaultManager, - string $proxyInterfaceName, + string|null $proxyInterfaceName, callable $managerFactory, ) { $this->managerFactory = $managerFactory; From b3bf81a82ef1e9a1f47c20a796c9c2c846e453be Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Nov 2025 19:26:52 +0000 Subject: [PATCH 03/10] Bump doctrine/.github from 12.1.0 to 12.2.0 Bumps [doctrine/.github](https://github.com/doctrine/.github) from 12.1.0 to 12.2.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/12.1.0...v12.2.0) --- updated-dependencies: - dependency-name: doctrine/.github dependency-version: 12.2.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/coding-standards.yml | 2 +- .github/workflows/continuous-integration.yml | 2 +- .github/workflows/documentation.yml | 2 +- .github/workflows/release-on-milestone-closed.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index 0ad9b907..dc0ed291 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -12,6 +12,6 @@ on: jobs: coding-standards: name: "Coding Standards" - uses: "doctrine/.github/.github/workflows/coding-standards.yml@12.1.0" + uses: "doctrine/.github/.github/workflows/coding-standards.yml@v12.2.0" with: composer-root-version: "3.0" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1db68268..1ccc9101 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -12,7 +12,7 @@ on: jobs: phpunit: name: "PHPUnit" - uses: "doctrine/.github/.github/workflows/continuous-integration.yml@12.1.0" + uses: "doctrine/.github/.github/workflows/continuous-integration.yml@v12.2.0" with: composer-root-version: "3.0" php-versions: '["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"]' diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 90c54d67..02088efa 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -17,4 +17,4 @@ on: jobs: documentation: name: "Documentation" - uses: "doctrine/.github/.github/workflows/documentation.yml@12.2.0" + uses: "doctrine/.github/.github/workflows/documentation.yml@v12.2.0" diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index 89dba39e..63421012 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -8,7 +8,7 @@ on: jobs: release: name: "Git tag, release & create merge-up PR" - uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@12.1.0" + uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@v12.2.0" secrets: GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 0f0fa07e..5031f618 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,6 +12,6 @@ on: jobs: static-analysis: name: "Static Analysis" - uses: "doctrine/.github/.github/workflows/phpstan.yml@12.1.0" + uses: "doctrine/.github/.github/workflows/phpstan.yml@v12.2.0" with: composer-root-version: "3.0" From 7ea41a89db4fcd429ca6d98427094125ba230011 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Tue, 4 Nov 2025 08:54:45 +0100 Subject: [PATCH 04/10] Backport static analysis fix --- src/Mapping/ClassMetadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mapping/ClassMetadata.php b/src/Mapping/ClassMetadata.php index c258aa2c..f66ee2e9 100644 --- a/src/Mapping/ClassMetadata.php +++ b/src/Mapping/ClassMetadata.php @@ -34,7 +34,7 @@ public function getIdentifier(); /** * Gets the ReflectionClass instance for this mapped class. * - * @return ReflectionClass + * @return ReflectionClass */ public function getReflectionClass(); From b5dab1231d33b74f01a868d6a34c8ff0715d5c5f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 19:57:36 +0000 Subject: [PATCH 05/10] Bump doctrine/.github/.github/workflows/phpstan.yml Bumps [doctrine/.github/.github/workflows/phpstan.yml](https://github.com/doctrine/.github) from 12.2.0 to 13.1.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/v12.2.0...13.1.0) --- updated-dependencies: - dependency-name: doctrine/.github/.github/workflows/phpstan.yml dependency-version: 13.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/static-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 5031f618..4e8075a7 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -12,6 +12,6 @@ on: jobs: static-analysis: name: "Static Analysis" - uses: "doctrine/.github/.github/workflows/phpstan.yml@v12.2.0" + uses: "doctrine/.github/.github/workflows/phpstan.yml@13.1.0" with: composer-root-version: "3.0" From 3957ae2974522648640bd3d2288744bc4ce71d70 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 19:57:37 +0000 Subject: [PATCH 06/10] Bump doctrine/.github/.github/workflows/documentation.yml Bumps [doctrine/.github/.github/workflows/documentation.yml](https://github.com/doctrine/.github) from 12.2.0 to 13.1.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/v12.2.0...13.1.0) --- updated-dependencies: - dependency-name: doctrine/.github/.github/workflows/documentation.yml dependency-version: 13.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/documentation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/documentation.yml b/.github/workflows/documentation.yml index 02088efa..2d63d1e5 100644 --- a/.github/workflows/documentation.yml +++ b/.github/workflows/documentation.yml @@ -17,4 +17,4 @@ on: jobs: documentation: name: "Documentation" - uses: "doctrine/.github/.github/workflows/documentation.yml@v12.2.0" + uses: "doctrine/.github/.github/workflows/documentation.yml@13.1.0" From 4e91a07082c0a1ddc3169f94fa28a3ba8a0356a1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 21:20:40 +0100 Subject: [PATCH 07/10] Bump doctrine/.github/.github/workflows/release-on-milestone-closed.yml (#480) Bumps [doctrine/.github/.github/workflows/release-on-milestone-closed.yml](https://github.com/doctrine/.github) from 12.2.0 to 13.1.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/v12.2.0...13.1.0) --- updated-dependencies: - dependency-name: doctrine/.github/.github/workflows/release-on-milestone-closed.yml dependency-version: 13.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release-on-milestone-closed.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml index 63421012..b82f876e 100644 --- a/.github/workflows/release-on-milestone-closed.yml +++ b/.github/workflows/release-on-milestone-closed.yml @@ -8,7 +8,7 @@ on: jobs: release: name: "Git tag, release & create merge-up PR" - uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@v12.2.0" + uses: "doctrine/.github/.github/workflows/release-on-milestone-closed.yml@13.1.0" secrets: GIT_AUTHOR_EMAIL: ${{ secrets.GIT_AUTHOR_EMAIL }} GIT_AUTHOR_NAME: ${{ secrets.GIT_AUTHOR_NAME }} From 5457688bbf6600df65cb96ebe7862ec5a6b54441 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 21:21:12 +0100 Subject: [PATCH 08/10] Bump doctrine/.github/.github/workflows/coding-standards.yml (#479) Bumps [doctrine/.github/.github/workflows/coding-standards.yml](https://github.com/doctrine/.github) from 12.2.0 to 13.1.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/v12.2.0...13.1.0) --- updated-dependencies: - dependency-name: doctrine/.github/.github/workflows/coding-standards.yml dependency-version: 13.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/coding-standards.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index dc0ed291..31d0b94f 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -12,6 +12,6 @@ on: jobs: coding-standards: name: "Coding Standards" - uses: "doctrine/.github/.github/workflows/coding-standards.yml@v12.2.0" + uses: "doctrine/.github/.github/workflows/coding-standards.yml@13.1.0" with: composer-root-version: "3.0" From 51521dea670374d47d23ec52a6671811bb6de453 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Nov 2025 21:21:43 +0100 Subject: [PATCH 09/10] Bump doctrine/.github/.github/workflows/continuous-integration.yml (#478) Bumps [doctrine/.github/.github/workflows/continuous-integration.yml](https://github.com/doctrine/.github) from 12.2.0 to 13.1.0. - [Release notes](https://github.com/doctrine/.github/releases) - [Commits](https://github.com/doctrine/.github/compare/v12.2.0...13.1.0) --- updated-dependencies: - dependency-name: doctrine/.github/.github/workflows/continuous-integration.yml dependency-version: 13.1.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/continuous-integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 1ccc9101..3b1ec4aa 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -12,7 +12,7 @@ on: jobs: phpunit: name: "PHPUnit" - uses: "doctrine/.github/.github/workflows/continuous-integration.yml@v12.2.0" + uses: "doctrine/.github/.github/workflows/continuous-integration.yml@13.1.0" with: composer-root-version: "3.0" php-versions: '["7.2", "7.3", "7.4", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5"]' From 4fd46d131a1cb642930e9307ff36de6930fe6248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 24 Nov 2025 21:26:39 +0100 Subject: [PATCH 10/10] Add support for Symfony 8 (#477) --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 47f5b93b..6741e58b 100644 --- a/composer.json +++ b/composer.json @@ -30,8 +30,8 @@ "phpstan/phpstan-strict-rules": "^2", "doctrine/coding-standard": "^14", "phpunit/phpunit": "^10.5.58 || ^12", - "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0", - "symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0" + "symfony/cache": "^4.4 || ^5.4 || ^6.0 || ^7.0 || ^8.0", + "symfony/finder": "^4.4 || ^5.4 || ^6.0 || ^7.0 || ^8.0" }, "autoload": { "psr-4": {