Skip to content

Commit 301c798

Browse files
feature #52032 [FrameworkBundle][Routing][Translation][Workflow] Move some compiler passes from FrameworkBundle to components (fancyweb)
This PR was merged into the 6.4 branch. Discussion ---------- [FrameworkBundle][Routing][Translation][Workflow] Move some compiler passes from FrameworkBundle to components | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | yes | Tickets | - | License | MIT Move `AddExpressionLanguageProvidersPass` to `symfony/routing` Move `DataCollectorTranslatorPass` and `LoggingTranslatorPass` to `symfony/translation` Move `WorkflowGuardListenerPass` to `symfony/workflow` Commits ------- 9bde6ce6cc [FrameworkBundle][Routing][Translation][Workflow] Move some compiler passes from FrameworkBundle to components
2 parents 97fea31 + 7d526cc commit 301c798

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CHANGELOG
1111
* Deprecate `AnnotationClassLoader`, use `AttributeClassLoader` instead
1212
* Deprecate `AnnotationDirectoryLoader`, use `AttributeDirectoryLoader` instead
1313
* Deprecate `AnnotationFileLoader`, use `AttributeFileLoader` instead
14+
* Add `AddExpressionLanguageProvidersPass` (moved from `FrameworkBundle`)
1415

1516
6.2
1617
---
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Reference;
17+
18+
/**
19+
* Registers the expression language providers.
20+
*
21+
* @author Fabien Potencier <fabien@symfony.com>
22+
*/
23+
class AddExpressionLanguageProvidersPass implements CompilerPassInterface
24+
{
25+
public function process(ContainerBuilder $container): void
26+
{
27+
if (!$container->has('router.default')) {
28+
return;
29+
}
30+
31+
$definition = $container->findDefinition('router.default');
32+
foreach ($container->findTaggedServiceIds('routing.expression_language_provider', true) as $id => $attributes) {
33+
$definition->addMethodCall('addExpressionLanguageProvider', [new Reference($id)]);
34+
}
35+
}
36+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Routing\Tests\DependencyInjection;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Definition;
17+
use Symfony\Component\DependencyInjection\Reference;
18+
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass;
19+
20+
class AddExpressionLanguageProvidersPassTest extends TestCase
21+
{
22+
public function testProcessForRouter()
23+
{
24+
$container = new ContainerBuilder();
25+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
26+
27+
$definition = new Definition(\stdClass::class);
28+
$definition->addTag('routing.expression_language_provider');
29+
$container->setDefinition('some_routing_provider', $definition->setPublic(true));
30+
31+
$container->register('router.default', \stdClass::class)->setPublic(true);
32+
$container->compile();
33+
34+
$router = $container->getDefinition('router.default');
35+
$calls = $router->getMethodCalls();
36+
$this->assertCount(1, $calls);
37+
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
38+
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
39+
}
40+
41+
public function testProcessForRouterAlias()
42+
{
43+
$container = new ContainerBuilder();
44+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
45+
46+
$definition = new Definition(\stdClass::class);
47+
$definition->addTag('routing.expression_language_provider');
48+
$container->setDefinition('some_routing_provider', $definition->setPublic(true));
49+
50+
$container->register('my_router', \stdClass::class)->setPublic(true);
51+
$container->setAlias('router.default', 'my_router');
52+
$container->compile();
53+
54+
$router = $container->getDefinition('my_router');
55+
$calls = $router->getMethodCalls();
56+
$this->assertCount(1, $calls);
57+
$this->assertEquals('addExpressionLanguageProvider', $calls[0][0]);
58+
$this->assertEquals(new Reference('some_routing_provider'), $calls[0][1][0]);
59+
}
60+
}

0 commit comments

Comments
 (0)