Skip to content

Commit b3367d9

Browse files
[DI][Config] Add & use ReflectionClassResource
1 parent 94df87e commit b3367d9

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

DependencyInjection/Compiler/LoggingTranslatorPass.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1617
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\Translation\TranslatorInterface;
19+
use Symfony\Component\Translation\TranslatorBagInterface;
1720

1821
/**
1922
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
@@ -31,7 +34,10 @@ public function process(ContainerBuilder $container)
3134
$definition = $container->getDefinition((string) $translatorAlias);
3235
$class = $container->getParameterBag()->resolveValue($definition->getClass());
3336

34-
if (is_subclass_of($class, 'Symfony\Component\Translation\TranslatorInterface') && is_subclass_of($class, 'Symfony\Component\Translation\TranslatorBagInterface')) {
37+
if (!$r = $container->getReflectionClass($class)) {
38+
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $translatorAlias));
39+
}
40+
if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) {
3541
$container->getDefinition('translator.logging')->setDecoratedService('translator');
3642
$container->getDefinition('translation.warmer')->replaceArgument(0, new Reference('translator.logging.inner'));
3743
}

Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public function testProcess()
5454
->method('getParameterBag')
5555
->will($this->returnValue($parameterBag));
5656

57+
$container->expects($this->once())
58+
->method('getReflectionClass')
59+
->with('Symfony\Bundle\FrameworkBundle\Translation\Translator')
60+
->will($this->returnValue(new \ReflectionClass('Symfony\Bundle\FrameworkBundle\Translation\Translator')));
61+
5762
$pass = new LoggingTranslatorPass();
5863
$pass->process($container);
5964
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"symfony/dependency-injection": "~3.3",
2323
"symfony/config": "~3.3",
2424
"symfony/event-dispatcher": "~3.3",
25-
"symfony/http-foundation": "~3.1",
25+
"symfony/http-foundation": "~3.3",
2626
"symfony/http-kernel": "~3.3",
2727
"symfony/polyfill-mbstring": "~1.0",
2828
"symfony/filesystem": "~2.8|~3.0",

0 commit comments

Comments
 (0)