Skip to content

Commit 1eee8ae

Browse files
committed
simplify TwigComponentPass
1 parent 5c82319 commit 1eee8ae

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/TwigComponent/src/DependencyInjection/Compiler/TwigComponentPass.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,12 @@ public function process(ContainerBuilder $container): void
3333
foreach (array_keys($container->findTaggedServiceIds('twig.component')) as $id) {
3434
$componentDefinition = $container->findDefinition($id);
3535

36-
$attributes = $container->getReflectionClass($componentDefinition->getClass())
37-
->getAttributes(AsTwigComponent::class, \ReflectionAttribute::IS_INSTANCEOF)
38-
;
39-
40-
if (!isset($attributes[0])) {
41-
throw new LogicException(sprintf('Service "%s" is tagged as a "twig.component" but does not have a "%s" class attribute.', $id, AsTwigComponent::class));
36+
try {
37+
$attribute = AsTwigComponent::forClass($componentDefinition->getClass());
38+
} catch (\InvalidArgumentException $e) {
39+
throw new LogicException(sprintf('Service "%s" is tagged as a "twig.component" but does not have a "%s" class attribute.', $id, AsTwigComponent::class), 0, $e);
4240
}
4341

44-
/** @var AsTwigComponent $attribute */
45-
$attribute = $attributes[0]->newInstance();
46-
4742
$componentMap[$attribute->getName()] = new Reference($id);
4843

4944
// component services must not be shared

0 commit comments

Comments
 (0)