Skip to content

Commit

Permalink
[DependencyInjection] Do not try to load default method name on inter…
Browse files Browse the repository at this point in the history
…face
  • Loading branch information
lyrixx committed Jul 25, 2024
1 parent 408b333 commit c840988
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Compiler/PriorityTaggedServiceTrait.php
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
8 changes: 8 additions & 0 deletions Tests/Compiler/PriorityTaggedServiceTraitTest.php
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;
}

0 comments on commit c840988

Please sign in to comment.