8000 reuse the reflector tracked by the container builder · symfony/symfony@b8b5fb4 · GitHub
[go: up one dir, main page]

Skip to content

Commit b8b5fb4

Browse files
committed
reuse the reflector tracked by the container builder
1 parent 04ee771 commit b8b5fb4

File tree

8000

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/Symfony/Component/DependencyInjection/Compiler/PriorityTaggedServiceTrait.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
6464
$definition = $container->getDefinition($serviceId);
6565
$class = $definition->getClass();
6666
$class = $container->getParameterBag()->resolveValue($class) ?: null;
67+
$reflector = null !== $class ? $container->getReflectionClass($class) : null;
6768
$checkTaggedItem = !$definition->hasTag($definition->isAutoconfigured() ? 'container.ignore_attributes' : $tagName);
6869

6970
foreach ($attributes as $attribute) {
7071
$index = $priority = null;
7172

7273
if (isset($attribute['priority'])) {
7374
$priority = $attribute['priority'];
74-
} elseif (null === $defaultPriority && $defaultPriorityMethod && $class) {
75-
$defaultPriority = PriorityTaggedServiceUtil::getDefault($container, $serviceId, $class, $defaultPriorityMethod, $tagName, 'priority', $checkTaggedItem);
75+
} elseif (null === $defaultPriority && $defaultPriorityMethod && $reflector) {
76+
$defaultPriority = PriorityTaggedServiceUtil::getDefault($serviceId, $reflector, $defaultPriorityMethod, $tagName, 'priority', $checkTaggedItem);
7677
}
7778
$priority ??= $defaultPriority ??= 0;
7879

@@ -84,17 +85,17 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
8485
if (null !== $indexAttribute && isset($attribute[$indexAttribute])) {
8586
$index = $parameterBag->resolveValue($attribute[$indexAttribute]);
8687
}
87-
if (null === $index && null === $defaultIndex && $defaultPriorityMethod && $class) {
88-
$defaultIndex = PriorityTaggedServiceUtil::getDefault($container, $serviceId, $class, $defaultIndexMethod ?? 'getDefaultName', $tagName, $indexAttribute, $checkTaggedItem);
88+
if (null === $index && null === $defaultIndex && $defaultPriorityMethod && $reflector) {
89+
$defaultIndex = PriorityTaggedServiceUtil::getDefault($serviceId, $reflector, $defaultIndexMethod ?? 'getDefaultName', $tagName, $indexAttribute, $checkTaggedItem);
8990
}
9091
$decorated = $definition->getTag('container.decorator')[0]['id'] ?? null;
9192
$index = $index ?? $defaultIndex ?? $defaultIndex = $decorated ?? $serviceId;
9293

9394
$services[] = [$priority, ++$i, $index, $serviceId, $class];
9495
}
9596

96-
if ($class) {
97-
$attributes = (new \ReflectionClass($class))->getAttributes(AsTaggedItem::class);
97+
if ($reflector) {
98+
$attributes = $reflector->getAttributes(AsTaggedItem::class);
9899
$attributeCount = \count($attributes);
99100

100101
foreach ($attributes as $attribute) {
@@ -137,9 +138,11 @@ private function findAndSortTaggedServices(string|TaggedIteratorArgument $tagNam
137138
*/
138139
class PriorityTaggedServiceUtil
139140
{
140-
public static function getDefault(ContainerBuilder $container, string $serviceId, string $class, string $defaultMethod, string $tagName, ?string $indexAttribute, bool $checkTaggedItem): string|int|null
141+
public static function getDefault(string $serviceId, \ReflectionClass $r, string $defaultMethod, string $tagName, ?string $indexAttribute, bool $checkTaggedItem): string|int|null
141142
{
142-
if (!($r = $container->getReflectionClass($class)) || (!$checkTaggedItem && !$r->hasMethod($defaultMethod))) {
143+
$class = $r->getName();
144+
145+
if (!$checkTaggedItem && !$r->hasMethod($defaultMethod)) {
143146
return null;
144147
}
145148

0 commit comments

Comments
 (0)
0