Skip to content

Commit 67ce52f

Browse files
committed
minor #18025 [2.7] Don't use reflection when possible (Ener-Getick)
This PR was merged into the 2.7 branch. Discussion ---------- [2.7] Don't use reflection when possible | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | See symfony/symfony#18021 Commits ------- 35be501 Don't use reflections when possible
2 parents 3f00bd4 + 36919da commit 67ce52f

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

DependencyInjection/Compiler/FragmentRendererPass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ public function process(ContainerBuilder $container)
3737
// We must assume that the class value has been correctly filled, even if the service is created by a factory
3838
$class = $container->getDefinition($id)->getClass();
3939

40-
$refClass = new \ReflectionClass($class);
4140
$interface = 'Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface';
42-
if (!$refClass->implementsInterface($interface)) {
41+
if (!is_subclass_of($class, $interface)) {
4342
throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
4443
}
4544

DependencyInjection/Compiler/LoggingTranslatorPass.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ public function process(ContainerBuilder $container)
3636
$definition = $container->getDefinition((string) $translatorAlias);
3737
$class = $container->getParameterBag()->resolveValue($definition->getClass());
3838

39-
$refClass = new \ReflectionClass($class);
40-
if ($refClass->implementsInterface('Symfony\Component\Translation\TranslatorInterface') && $refClass->implementsInterface('Symfony\Component\Translation\TranslatorBagInterface')) {
39+
if (is_subclass_of($class, 'Symfony\Component\Translation\TranslatorInterface') && is_subclass_of($class, 'Symfony\Component\Translation\TranslatorBagInterface')) {
4140
$container->getDefinition('translator.logging')->setDecoratedService('translator');
4241
$container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner'));
4342
}

0 commit comments

Comments
 (0)