From 246164f74834f41aeab58bb4ae0c345c34e59784 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 25 Nov 2018 12:15:31 +0100 Subject: [PATCH] [DI] fix copying expression providers when analyzing the service graph --- .../Compiler/InlineServiceDefinitionsPass.php | 3 ++ .../CustomExpressionLanguageFunctionTest.php | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 src/Symfony/Component/DependencyInjection/Tests/Compiler/CustomExpressionLanguageFunctionTest.php diff --git a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php index eb89a2a40d..6049b3eefd 100644 --- a/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php +++ b/src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php @@ -53,6 +53,9 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe $analyzedContainer = new ContainerBuilder(); $analyzedContainer->setAliases($container->getAliases()); $analyzedContainer->setDefinitions($container->getDefinitions()); + foreach ($container->getExpressionLanguageProviders() as $provider) { + $analyzedContainer->addExpressionLanguageProvider($provider); + } } else { $analyzedContainer = $container; } diff --git a/src/Symfony/Component/DependencyInjection/Tests/Compiler/CustomExpressionLanguageFunctionTest.php b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CustomExpressionLanguageFunctionTest.php new file mode 100644 index 0000000000..ead0a4207a --- /dev/null +++ b/src/Symfony/Component/DependencyInjection/Tests/Compiler/CustomExpressionLanguageFunctionTest.php @@ -0,0 +1,36 @@ +register('test', 'stdClass') + ->setPublic(true) + ->setArguments(array(new Expression('custom_func("foobar")'))); + + $container->addExpressionLanguageProvider(new class() implements ExpressionFunctionProviderInterface { + public function getFunctions() + { + return array( + ExpressionFunction::fromPhp('strtolower', 'custom_func'), + ); + } + }); + $container->compile(); + + $dump = new PhpDumper($container); + $dumped = $dump->dump(); + + $this->assertContains('strtolower("foobar")', $dumped); + } +}