[DI] fix copying expression providers when analyzing the service graph

This commit is contained in:
Nicolas Grekas 2018-11-25 12:15:31 +01:00
parent 4c1e8bd836
commit 246164f748
2 changed files with 39 additions and 0 deletions

View File

@ -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;
}

View File

@ -0,0 +1,36 @@
<?php
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
class CustomExpressionLanguageFunctionTest extends TestCase
{
public function testDump()
{
$container = new ContainerBuilder();
$container->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);
}
}