Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Persistence/AbstractManagerRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,23 @@ 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<string, string> $connections
* @param array<string, string> $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,
array $connections,
array $managers,
string $defaultConnection,
string $defaultManager,
string $proxyInterfaceName
?string $proxyInterfaceName = null
) {
$this->name = $name;
$this->connections = $connections;
Expand Down Expand Up @@ -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) {
Expand Down
22 changes: 20 additions & 2 deletions tests/Persistence/ManagerRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -185,15 +203,15 @@ class TestManagerRegistry extends AbstractManagerRegistry
/**
* {@inheritDoc}
*
* @phpstan-param class-string $proxyInterfaceName
* @phpstan-param class-string|null $proxyInterfaceName
*/
public function __construct(
string $name,
array $connections,
array $managers,
string $defaultConnection,
string $defaultManager,
string $proxyInterfaceName,
?string $proxyInterfaceName,
callable $managerFactory
) {
$this->managerFactory = $managerFactory;
Expand Down