Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 246164f

Browse files
[DI] fix copying expression providers when analyzing the service graph
1 parent 4c1e8bd commit 246164f

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/Symfony/Component/DependencyInjection/Compiler/InlineServiceDefinitionsPass.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public function process(ContainerBuilder $container)
5353
$analyzedContainer = new ContainerBuilder();
5454
$analyzedContainer->setAliases($container->getAliases());
5555
$analyzedContainer->setDefinitions($container->getDefinitions());
56+
foreach ($container->getExpressionLanguageProviders() as $provider) {
57+
$analyzedContainer->addExpressionLanguageProvider($provider);
58+
}
5659
} else {
5760
$analyzedContainer = $container;
5861
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Symfony\Component\DependencyInjection\Dumper\PhpDumper;
8+
use Symfony\Component\ExpressionLanguage\Expression;
9+
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
10+
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
11+
12+
class CustomExpressionLanguageFunctionTest extends TestCase
13+
{
14+
public function testDump()
15+
{
16+
$container = new ContainerBuilder();
17+
$container->register('test', 'stdClass')
18+
->setPublic(true)
19+
->setArguments(array(new Expression('custom_func("foobar")')));
20+
21+
$container->addExpressionLanguageProvider(new class() implements ExpressionFunctionProviderInterface {
22+
public function getFunctions()
23+
{
24+
return array(
25+
ExpressionFunction::fromPhp('strtolower', 'custom_func'),
26+
);
27+
}
28+
});
29+
$container->compile();
30+
31+
$dump = new PhpDumper($container);
32+
$dumped = $dump->dump();
33+
34+
$this->assertContains('strtolower("foobar")', $dumped);
35+
}
36+
}

0 commit comments

Comments
 (0)