Skip to content

Commit d59e6ef

Browse files
authored
Revert MappingDriverChain namespace matching fix (#455)
1 parent 06a5956 commit d59e6ef

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/Persistence/Mapping/Driver/MappingDriverChain.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Doctrine\Persistence\Mapping\MappingException;
99

1010
use function array_keys;
11-
use function rtrim;
1211
use function spl_object_hash;
1312
use function strpos;
1413

@@ -74,7 +73,7 @@ public function getDrivers()
7473
public function loadMetadataForClass(string $className, ClassMetadata $metadata)
7574
{
7675
foreach ($this->drivers as $namespace => $driver) {
77-
if ($this->isInNamespace($className, $namespace)) {
76+
if (strpos($className, $namespace) === 0) {
7877
$driver->loadMetadataForClass($className, $metadata);
7978

8079
return;
@@ -106,7 +105,7 @@ public function getAllClassNames()
106105
}
107106

108107
foreach ($driverClasses[$oid] as $className) {
109-
if (! $this->isInNamespace($className, $namespace)) {
108+
if (strpos($className, $namespace) !== 0) {
110109
continue;
111110
}
112111

@@ -129,7 +128,7 @@ public function getAllClassNames()
129128
public function isTransient(string $className)
130129
{
131130
foreach ($this->drivers as $namespace => $driver) {
132-
if ($this->isInNamespace($className, $namespace)) {
131+
if (strpos($className, $namespace) === 0) {
133132
return $driver->isTransient($className);
134133
}
135134
}
@@ -140,11 +139,4 @@ public function isTransient(string $className)
140139

141140
return true;
142141
}
143-
144-
private function isInNamespace(string $className, string $namespace): bool
145-
{
146-
$namespace = rtrim($namespace, '\\') . '\\';
147-
148-
return strpos($className, $namespace) === 0;
149-
}
150142
}

tests/Persistence/Mapping/DriverChainTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
class DriverChainTest extends DoctrineTestCase
1717
{
1818
/**
19-
* @testWith ["Doctrine\\Tests\\Models\\Company"]
20-
* ["Doctrine\\Tests\\Persistence\\Map"]
19+
* @testWith ["Doctrine\\Tests\\Models\\Company", "Doctrine\\Tests\\Persistence\\Mapping"]
20+
* ["Doctrine\\Tests\\Persistence\\Map\\", "Doctrine\\Tests\\Persistence\\Map"]
2121
*/
22-
public function testDelegateToMatchingNamespaceDriver(string $namespace): void
22+
public function testDelegateToMatchingNamespaceDriver(string $namespace1, string $namespace2): void
2323
{
2424
$className = DriverChainEntity::class;
2525
$classMetadata = $this->createMock(ClassMetadata::class);
@@ -41,8 +41,8 @@ public function testDelegateToMatchingNamespaceDriver(string $namespace): void
4141
->with(self::equalTo($className))
4242
->willReturn(true);
4343

44-
$chain->addDriver($driver1, $namespace);
45-
$chain->addDriver($driver2, 'Doctrine\Tests\Persistence\Mapping');
44+
$chain->addDriver($driver1, $namespace1);
45+
$chain->addDriver($driver2, $namespace2);
4646

4747
$chain->loadMetadataForClass($className, $classMetadata);
4848

0 commit comments

Comments
 (0)