8000 feature #52032 [FrameworkBundle][Routing][Translation][Workflow] Move… · symfony/symfony@f5178e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit f5178e0

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 ------- 9bde6ce [FrameworkBundle][Routing][Translation][Workflow] Move some compiler passes from FrameworkBundle to components
2 parents 5301b00 + 9bde6ce commit f5178e0

22 files changed

+590
-9
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ CHANGELOG
3838
* Deprecate the `routing.loader.annotation.directory` service, use the `routing.loader.attribute.directory` service instead
3939
* Deprecate the `routing.loader.annotation.file` service, use the `routing.loader.attribute.file` service instead
4040
* Deprecate `AnnotatedRouteControllerLoader`, use `AttributeRouteControllerLoader` instead
41+
* Deprecate `AddExpressionLanguageProvidersPass`, use `Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass` instead
42+
* Deprecate `DataCollectorTranslatorPass`, use `Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass` instead
43+
* Deprecate `LoggingTranslatorPass`, use `Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass` instead
44+
* Deprecate `WorkflowGuardListenerPass`, use `Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass` instead
4145

4246
6.3
4347
---

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/AddExpressionLanguageProvidersPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Reference;
1717

18+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AddExpressionLanguageProvidersPass::class, \Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass::class);
19+
1820
/**
1921
* Registers the expression language providers.
2022
*
2123
* @author Fabien Potencier <fabien@symfony.com>
24+
*
25+
* @deprecated since Symfony 6.4, use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass instead.
2226
*/
2327
class AddExpressionLanguageProvidersPass implements CompilerPassInterface
2428
{

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/DataCollectorTranslatorPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\Translation\TranslatorBagInterface;
1717

18+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', DataCollectorTranslatorPass::class, \Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass::class);
19+
1820
/**
1921
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
22+
*
23+
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass instead.
2024
*/
2125
class DataCollectorTranslatorPass implements CompilerPassInterface
2226< 10000 div class="diff-text-inner">{

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/LoggingTranslatorPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
use Symfony\Component\Translation\TranslatorBagInterface;
1818
use Symfony\Contracts\Translation\TranslatorInterface;
1919

20+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', LoggingTranslatorPass::class, \Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass::class);
21+
2022
/**
2123
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
24+
*
25+
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass instead.
2226
*/
2327
class LoggingTranslatorPass implements CompilerPassInterface
2428
{

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/WorkflowGuardListenerPass.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
1616
use Symfony\Component\DependencyInjection\Exception\LogicException;
1717

18+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', WorkflowGuardListenerPass::class, \Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass::class);
19+
1820
/**
1921
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
2022
* @author Grégoire Pineau <lyrixx@lyrixx.info>
23+
*
24+
* @deprecated since Symfony 6.4, use Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass instead.
2125
*/
2226
class WorkflowGuardListenerPass implements CompilerPassInterface
2327
{

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
1515
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddDebugLogProcessorPass;
16-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
1716
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AssetsContextPass;
1817
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
19-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
2018
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ErrorLoggerCompilerPass;
21-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2219
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
2320
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RemoveUnusedSessionMarshallingHandlerPass;
2421
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2522
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerWeakRefPass;
2623
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
27-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
2824
use Symfony\Component\Cache\Adapter\ApcuAdapter;
2925
use Symfony\Component\Cache\Adapter\ArrayAdapter;
3026
use Symfony\Component\Cache\Adapter\ChainAdapter;
@@ -59,9 +55,12 @@
5955
use Symfony\Component\Messenger\DependencyInjection\MessengerPass;
6056
use Symfony\Component\Mime\DependencyInjection\AddMimeTypeGuesserPass;
6157
use Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass;
58+
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass;
6259
use Symfony\Component\Routing\DependencyInjection\RoutingResolverPass;
6360
use Symfony\Component\Scheduler\DependencyInjection\AddScheduleMessengerPass;
6461
use Symfony\Component\Serializer\DependencyInjection\SerializerPass;
62+
use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass;
63+
use Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass;
6564
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
6665
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
6766
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
@@ -71,6 +70,7 @@
7170
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
7271
use Symfony\Component\VarExporter\Internal\Hydrator;
7372
use Symfony\Component\VarExporter\Internal\Registry;
73+
use Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass;
7474

7575
// Help opcache.preload discover always-needed symbols
7676
class_exists(ApcuAdapter::class);
@@ -157,7 +157,7 @@ public function build(ContainerBuilder $container)
157157
$this->addCompilerPassIfExists($container, TranslatorPass::class, PassConfig::TYPE_BEFORE_OPTIMIZATION, -32);
158158
$this->addCompilerPassIfExists($container, TranslatorPathsPass::class, PassConfig::TYPE_AFTER_REMOVING);
159159
$container->addCompilerPass(new LoggingTranslatorPass());
160-
$container->addCompilerPass(new AddExpressionLanguageProvidersPass(false));
160+
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
161161
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
162162
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
163163
$container->addCompilerPass(new FragmentRendererPass());

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/AddExpressionLanguageProvidersPassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\DependencyInjection\Definition;
1818
use Symfony\Component\DependencyInjection\Reference;
1919

20+
/**
21+
* @group legacy
22+
*/
2023
class AddExpressionLanguageProvidersPassTest extends TestCase
2124
{
2225
public function testProcessForRouter()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
use Symfony\Component\Translation\Translator;
2121
use Symfony\Contracts\Translation\TranslatorInterface;
2222

23+
/**
24+
* @group legacy
25+
*/
2326
class DataCollectorTranslatorPassTest extends TestCase
2427
{
2528
private ContainerBuilder $container;

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/LoggingTranslatorPassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
use Symfony\Component\DependencyInjection\Reference;
1818
use Symfony\Component\Translation\Translator;
1919

20+
/**
21+
* @group legacy
22+
*/
2023
class LoggingTranslatorPassTest extends TestCase
2124
{
2225
public function testProcess()

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Compiler/WorkflowGuardListenerPassTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
use Symfony\Component\Security\Core\Role\RoleHierarchy;
2222
use Symfony\Component\Validator\Validator\ValidatorInterface;
2323

24+
/**
25+
* @group legacy
26+
*/
2427
class WorkflowGuardListenerPassTest extends TestCase
2528
{
2629
private ContainerBuilder $container;

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@
6262
"symfony/serializer": "^6.4|^7.0",
6363
"symfony/stopwatch": "^5.4|^6.0|^7.0",
6464
"symfony/string": "^5.4|^6.0|^7.0",
65-
"symfony/translation": "^6.2.8|^7.0",
65+
"symfony/translation": "^6.4|^7.0",
6666
"symfony/twig-bundle": "^5.4|^6.0|^7.0",
6767
"symfony/validator": "^6.4|^7.0",
68-
"symfony/workflow": "^5.4|^6.0|^7.0",
68+
"symfony/workflow": "^6.4|^7.0",
6969
"symfony/yaml": "^5.4|^6.0|^7.0",
7070
"symfony/property-info": "^5.4|^6.0|^7.0",
7171
"symfony/uid": "^5.4|^6.0|^7.0",
@@ -96,12 +96,12 @@
9696
"symfony/security-csrf": "<5.4",
9797
"symfony/security-core": "<5.4",
9898
"symfony/stopwatch": "<5.4",
99-
"symfony/translation": "<6.2.8",
99+
"symfony/translation": "<6.4",
100100
"symfony/twig-bridge": "<5.4",
101101
"symfony/twig-bundle": "<5.4",
102102
"symfony/validator": "<6.4",
103103
"symfony/web-profiler-bundle": "<5.4",
104-
"symfony/workflow": "<5.4"
104+
"symfony/workflow": "<6.4"
105105
},
106106
"autoload": {
107107
"psr-4": { "Symfony\\Bundle\\FrameworkBundle\\": "" },

src/Symfony/Component/Routing/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+
}

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CHANGELOG
77
* Give current locale to `LocaleSwitcher::runWithLocale()`'s callback
88
* Add `--as-tree` option to `translation:pull` command to write YAML messages as a tree-like structure
99
* [BC BREAK] Add argument `$buildDir` to `DataCollectorTranslator::warmUp()`
10+
* Add `DataCollectorTranslatorPass` and `LoggingTranslatorPass` (moved from `FrameworkBundle`)
1011

1112
6.3
1213
---
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\Translation\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\Translation\TranslatorBagInterface;
17+
18+
/**
19+
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
20+
*/
21+
class DataCollectorTranslatorPass implements CompilerPassInterface
22+
{
23+
public function process(ContainerBuilder $container): void
24+
{
25+
if (!$container->has('translator')) {
26+
return;
27+
}
28+
29+
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
30+
31+
if (!is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
32+
$container->removeDefinition('translator.data_collector');
33+
$container->removeDefinition('data_collector.translation');
34+
}
35+
}
36+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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\Translation\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15+
use Symfony\Component\DependencyInjection\ContainerBuilder;
16+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
17+
use Symfony\Component\Translation\TranslatorBagInterface;
18+
use Symfony\Contracts\Translation\TranslatorInterface;
19+
20+
/**
21+
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
22+
*/
23+
class LoggingTranslatorPass implements CompilerPassInterface
24+
{
25+
public function process(ContainerBuilder $container): void
26+
{
27+
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
28+
return;
29+
}
30+
31+
if (!$container->hasParameter('translator.logging') || !$container->getParameter('translator.logging')) {
32+
return;
33+
}
34+
35+
$translatorAlias = $container->getAlias('translator');
36+
$definition = $container->getDefinition((string) $translatorAlias);
37+
$class = $container->getParameterBag()->resolveValue($definition->getClass());
38+
39+
if (!$r = $container->getReflectionClass($class)) {
40+
throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $translatorAlias));
41+
}
42+
43+
if (!$r->isSubclassOf(TranslatorInterface::class) || !$r->isSubclassOf(TranslatorBagInterface::class)) {
44+
return;
45+
}
46+
47+
$container->getDefinition('translator.logging')->setDecoratedService('translator');
48+
$warmer = $container->getDefinition('translation.warmer');
49+
$subscriberAttributes = $warmer->getTag('container.service_subscriber');
50+
$warmer->clearTag('container.service_subscriber');
51+
52+
foreach ($subscriberAttributes as $k => $v) {
53+
if ((!isset($v['id']) || 'translator' !== $v['id']) && (!isset($v['key']) || 'translator' !== $v['key'])) {
54+
$warmer->addTag('container.service_subscriber', $v);
55+
}
56+
}
57+
$warmer->addTag('container.service_subscriber', ['key' => 'translator', 'id' => 'translator.logging.inner']);
58+
}
59+
}

0 commit comments

Comments
 (0)
0