[DI] fix detecting singly implemented interfaces
This commit is contained in:
parent
29a2f17124
commit
eccb937d97
@ -112,7 +112,7 @@ abstract class FileLoader extends BaseFileLoader
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
foreach (class_implements($class, false) as $interface) {
|
foreach (class_implements($class, false) as $interface) {
|
||||||
$this->singlyImplemented[$interface] = isset($this->singlyImplemented[$interface]) ? false : $class;
|
$this->singlyImplemented[$interface] = ($this->singlyImplemented[$interface] ?? $class) !== $class ? false : $class;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,6 +91,8 @@ class FileLoaderTest extends TestCase
|
|||||||
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
|
$loader = new TestFileLoader($container, new FileLocator(self::$fixturesPath.'/Fixtures'));
|
||||||
|
|
||||||
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
|
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*');
|
||||||
|
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\Sub\\', 'Prototype/%sub_dir%/*'); // loading twice should not be an issue
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
['service_container', Bar::class],
|
['service_container', Bar::class],
|
||||||
@ -119,6 +121,7 @@ class FileLoaderTest extends TestCase
|
|||||||
// load everything, except OtherDir/AnotherSub & Foo.php
|
// load everything, except OtherDir/AnotherSub & Foo.php
|
||||||
'Prototype/{%other_dir%/AnotherSub,Foo.php}'
|
'Prototype/{%other_dir%/AnotherSub,Foo.php}'
|
||||||
);
|
);
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
|
|
||||||
$this->assertTrue($container->has(Bar::class));
|
$this->assertTrue($container->has(Bar::class));
|
||||||
$this->assertTrue($container->has(Baz::class));
|
$this->assertTrue($container->has(Baz::class));
|
||||||
@ -148,6 +151,8 @@ class FileLoaderTest extends TestCase
|
|||||||
'Prototype/OtherDir/AnotherSub/DeeperBaz.php',
|
'Prototype/OtherDir/AnotherSub/DeeperBaz.php',
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
|
|
||||||
$this->assertTrue($container->has(Foo::class));
|
$this->assertTrue($container->has(Foo::class));
|
||||||
$this->assertTrue($container->has(Baz::class));
|
$this->assertTrue($container->has(Baz::class));
|
||||||
$this->assertFalse($container->has(Bar::class));
|
$this->assertFalse($container->has(Bar::class));
|
||||||
@ -162,6 +167,7 @@ class FileLoaderTest extends TestCase
|
|||||||
$prototype = new Definition();
|
$prototype = new Definition();
|
||||||
$prototype->setPublic(true)->setPrivate(true);
|
$prototype->setPublic(true)->setPrivate(true);
|
||||||
$loader->registerClasses($prototype, 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/*');
|
$loader->registerClasses($prototype, 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/*');
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
|
|
||||||
$this->assertTrue($container->has(Bar::class));
|
$this->assertTrue($container->has(Bar::class));
|
||||||
$this->assertTrue($container->has(Baz::class));
|
$this->assertTrue($container->has(Baz::class));
|
||||||
@ -193,6 +199,7 @@ class FileLoaderTest extends TestCase
|
|||||||
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
|
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
|
||||||
'Prototype/%bad_classes_dir%/*'
|
'Prototype/%bad_classes_dir%/*'
|
||||||
);
|
);
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
|
|
||||||
$this->assertTrue($container->has(MissingParent::class));
|
$this->assertTrue($container->has(MissingParent::class));
|
||||||
|
|
||||||
@ -211,6 +218,7 @@ class FileLoaderTest extends TestCase
|
|||||||
|
|
||||||
// the Sub is missing from namespace prefix
|
// the Sub is missing from namespace prefix
|
||||||
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/Sub/*');
|
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/Sub/*');
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRegisterClassesWithIncompatibleExclude()
|
public function testRegisterClassesWithIncompatibleExclude()
|
||||||
@ -226,6 +234,7 @@ class FileLoaderTest extends TestCase
|
|||||||
'Prototype/*',
|
'Prototype/*',
|
||||||
'yaml/*'
|
'yaml/*'
|
||||||
);
|
);
|
||||||
|
$loader->registerAliasesForSinglyImplementedInterfaces();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,10 +249,4 @@ class TestFileLoader extends FileLoader
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
|
|
||||||
{
|
|
||||||
parent::registerClasses($prototype, $namespace, $resource, $exclude);
|
|
||||||
$this->registerAliasesForSinglyImplementedInterfaces();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user