bug #29315 [DI] fix copying expression providers when analyzing the service graph (nicolas-grekas)
This PR was merged into the 4.2-dev branch.
Discussion
----------
[DI] fix copying expression providers when analyzing the service graph
| Q | A
| ------------- | ---
| Branch? | 4.2
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | #29304
| License | MIT
| Doc PR | -
Courtesy of @mishal, thanks for providing all the details.
Commits
-------
246164f748
[DI] fix copying expression providers when analyzing the service graph
This commit is contained in:
commit
14931b182f
@ -53,6 +53,9 @@ class InlineServiceDefinitionsPass extends AbstractRecursivePass implements Repe
|
|||||||
$analyzedContainer = new ContainerBuilder();
|
$analyzedContainer = new ContainerBuilder();
|
||||||
$analyzedContainer->setAliases($container->getAliases());
|
$analyzedContainer->setAliases($container->getAliases());
|
||||||
$analyzedContainer->setDefinitions($container->getDefinitions());
|
$analyzedContainer->setDefinitions($container->getDefinitions());
|
||||||
|
foreach ($container->getExpressionLanguageProviders() as $provider) {
|
||||||
|
$analyzedContainer->addExpressionLanguageProvider($provider);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$analyzedContainer = $container;
|
$analyzedContainer = $container;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user