8000 [DI] fix detecting singly implemented interfaces by nicolas-grekas · Pull Request #34370 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] fix detecting singly implemented interfaces #34370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 14, 2019
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
[DI] fix detecting singly implemented interfaces
  • Loading branch information
nicolas-grekas committed Nov 13, 2019
commit eccb937d975d90b92e52e9ae689a7d1344d99400
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function registerClasses(Definition $prototype, $namespace, $resource, $e
continue;
}
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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ public function testRegisterClasses()
$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%/*'); // loading twice should not be an issue
$loader->registerAliasesForSinglyImplementedInterfaces();

$this->assertEquals(
['service_container', Bar::class],
Expand Down Expand Up @@ -119,6 +121,7 @@ public function testRegisterClassesWithExclude()
// load everything, except OtherDir/AnotherSub & Foo.php
'Prototype/{%other_dir%/AnotherSub,Foo.php}'
);
$loader->registerAliasesForSinglyImplementedInterfaces();

$this->assertTrue($container->has(Bar::class));
$this->assertTrue($container->has(Baz::class));
Expand Down Expand Up @@ -148,6 +151,8 @@ public function testRegisterClassesWithExcludeAsArray()
'Prototype/OtherDir/AnotherSub/DeeperBaz.php',
]
);
$loader->registerAliasesForSinglyImplementedInterfaces();

$this->assertTrue($container->has(Foo::class));
$this->assertTrue($container->has(Baz::class));
$this->assertFalse($container->has(Bar::class));
Expand All @@ -162,6 +167,7 @@ public function testNestedRegisterClasses()
$prototype = new Definition();
$prototype->setPublic(true)->setPrivate(true);
$loader->registerClasses($prototype, 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/*');
$loader->registerAliasesForSinglyImplementedInterfaces();

$this->assertTrue($container->has(Bar::class));
$this->assertTrue($container->has(Baz::class));
Expand Down Expand Up @@ -193,6 +199,7 @@ public function testMissingParentClass()
'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\BadClasses\\',
'Prototype/%bad_classes_dir%/*'
);
$loader->registerAliasesForSinglyImplementedInterfaces();

$this->assertTrue($container->has(MissingParent::class));

Expand All @@ -211,6 +218,7 @@ public function testRegisterClassesWithBadPrefix()

// the Sub is missing from namespace prefix
$loader->registerClasses(new Definition(), 'Symfony\Component\DependencyInjection\Tests\Fixtures\Prototype\\', 'Prototype/Sub/*');
$loader->registerAliasesForSinglyImplementedInterfaces();
}

public function testRegisterClassesWithIncompatibleExclude()
Expand All @@ -226,6 +234,7 @@ public function testRegisterClassesWithIncompatibleExclude()
'Prototype/*',
'yaml/*'
);
$loader->registerAliasesForSinglyImplementedInterfaces();
}
}

Expand All @@ -240,10 +249,4 @@ public function supports($resource, $type = null): bool
{
return false;
}

public function registerClasses(Definition $prototype, $namespace, $resource, $exclude = null)
{
parent::registerClasses($prototype, $namespace, $resource, $exclude);
$this->registerAliasesForSinglyImplementedInterfaces();
}
}
0