Skip to content
Merged
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
14 changes: 3 additions & 11 deletions src/Persistence/Mapping/Driver/MappingDriverChain.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Doctrine\Persistence\Mapping\MappingException;

use function array_keys;
use function rtrim;
use function spl_object_hash;
use function strpos;

Expand Down Expand Up @@ -74,7 +73,7 @@ public function getDrivers()
public function loadMetadataForClass(string $className, ClassMetadata $metadata)
{
foreach ($this->drivers as $namespace => $driver) {
if ($this->isInNamespace($className, $namespace)) {
if (strpos($className, $namespace) === 0) {
$driver->loadMetadataForClass($className, $metadata);

return;
Expand Down Expand Up @@ -106,7 +105,7 @@ public function getAllClassNames()
}

foreach ($driverClasses[$oid] as $className) {
if (! $this->isInNamespace($className, $namespace)) {
if (strpos($className, $namespace) !== 0) {
continue;
}

Expand All @@ -129,7 +128,7 @@ public function getAllClassNames()
public function isTransient(string $className)
{
foreach ($this->drivers as $namespace => $driver) {
if ($this->isInNamespace($className, $namespace)) {
if (strpos($className, $namespace) === 0) {
return $driver->isTransient($className);
}
}
Expand All @@ -140,11 +139,4 @@ public function isTransient(string $className)

return true;
}

private function isInNamespace(string $className, string $namespace): bool
{
$namespace = rtrim($namespace, '\\') . '\\';

return strpos($className, $namespace) === 0;
}
}
10 changes: 5 additions & 5 deletions tests/Persistence/Mapping/DriverChainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
class DriverChainTest extends DoctrineTestCase
{
/**
* @testWith ["Doctrine\\Tests\\Models\\Company"]
* ["Doctrine\\Tests\\Persistence\\Map"]
* @testWith ["Doctrine\\Tests\\Models\\Company", "Doctrine\\Tests\\Persistence\\Mapping"]
* ["Doctrine\\Tests\\Persistence\\Map\\", "Doctrine\\Tests\\Persistence\\Map"]
*/
public function testDelegateToMatchingNamespaceDriver(string $namespace): void
public function testDelegateToMatchingNamespaceDriver(string $namespace1, string $namespace2): void
{
$className = DriverChainEntity::class;
$classMetadata = $this->createMock(ClassMetadata::class);
Expand All @@ -41,8 +41,8 @@ public function testDelegateToMatchingNamespaceDriver(string $namespace): void
->with(self::equalTo($className))
->willReturn(true);

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

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

Expand Down