diff --git a/src/Persistence/AbstractManagerRegistry.php b/src/Persistence/AbstractManagerRegistry.php index ce27d99f..a2ce0383 100644 --- a/src/Persistence/AbstractManagerRegistry.php +++ b/src/Persistence/AbstractManagerRegistry.php @@ -31,15 +31,15 @@ abstract class AbstractManagerRegistry implements ManagerRegistry private $defaultManager; /** - * @var string - * @phpstan-var class-string + * @var string|null + * @phpstan-var class-string|null */ private $proxyInterfaceName; /** * @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( string $name, @@ -47,7 +47,7 @@ public function __construct( array $managers, string $defaultConnection, string $defaultManager, - string $proxyInterfaceName + ?string $proxyInterfaceName = null ) { $this->name = $name; $this->connections = $connections; @@ -177,7 +177,7 @@ public function getManagerForClass(string $class) return null; } - if ($proxyClass->implementsInterface($this->proxyInterfaceName)) { + if ($this->proxyInterfaceName !== null && $proxyClass->implementsInterface($this->proxyInterfaceName)) { $parentClass = $proxyClass->getParentClass(); if ($parentClass === false) { diff --git a/tests/Persistence/ManagerRegistryTest.php b/tests/Persistence/ManagerRegistryTest.php index 96177557..1cf13cb1 100644 --- a/tests/Persistence/ManagerRegistryTest.php +++ b/tests/Persistence/ManagerRegistryTest.php @@ -154,6 +154,24 @@ public function testGetRepositoryWithManagerDetection(): void self::assertSame($repository, $this->mr->getRepository(OtherTestObject::class)); } + public function testNoProxyClass(): void + { + $mr = new TestManagerRegistry( + 'ORM', + ['default' => 'default_connection'], + ['default' => 'default_manager'], + 'default', + 'default', + null, + $this->getManagerFactory() + ); + + self::assertInstanceOf( + ObjectManager::class, + $mr->getManagerForClass(TestObject::class) + ); + } + private function getManagerFactory(): Closure { return function (string $name) { @@ -185,7 +203,7 @@ class TestManagerRegistry extends AbstractManagerRegistry /** * {@inheritDoc} * - * @phpstan-param class-string $proxyInterfaceName + * @phpstan-param class-string|null $proxyInterfaceName */ public function __construct( string $name, @@ -193,7 +211,7 @@ public function __construct( array $managers, string $defaultConnection, string $defaultManager, - string $proxyInterfaceName, + ?string $proxyInterfaceName, callable $managerFactory ) { $this->managerFactory = $managerFactory;