Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DependencyInjection] Do not try to load default method name on interface #57832

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
Jul 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ public static function getDefault(ContainerBuilder $container, string $serviceId
return null;
}

if ($r->isInterface()) {
return null;
}

if (null !== $indexAttribute) {
$service = $class !== $serviceId ? sprintf('service "%s"', $serviceId) : 'on the corresponding service';
$message = [sprintf('Either method "%s::%s()" should ', $class, $defaultMethod), sprintf(' or tag "%s" on %s is missing attribute "%s".', $tagName, $service, $indexAttribute)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,16 @@ public function testTheIndexedTagsByDefaultIndexMethod()

$container->register('service3', IntTagClass::class)->addTag('my_custom_tag');

$container->register('service4', HelloInterface::class)->addTag('my_custom_tag');

$priorityTaggedServiceTraitImplementation = new PriorityTaggedServiceTraitImplementation();

$tag = new TaggedIteratorArgument('my_custom_tag', 'foo', 'getFooBar');
$expected = [
'bar_tab_class_with_defaultmethod' => new TypedReference('service2', BarTagClass::class),
'service1' => new TypedReference('service1', FooTagClass::class),
'10' => new TypedReference('service3', IntTagClass::class),
'service4' => new TypedReference('service4', HelloInterface::class),
];
$services = $priorityTaggedServiceTraitImplementation->test($tag, $container);
$this->assertSame(array_keys($expected), array_keys($services));
Expand Down Expand Up @@ -244,3 +247,8 @@ class HelloNamedService extends \stdClass
class HelloNamedService2
{
}

interface HelloInterface
{
public static function getFooBar(): string;
}