Skip to content

Commit 058c80e

Browse files
committed
[FrameworkBundle][Routing][Translation][Workflow] Move some compiler passes from FrameworkBundle to components
1 parent 1f2ec3e commit 058c80e

22 files changed

+596
-119
lines changed

src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ CHANGELOG
3131
* Deprecate the `framework.asset_mapper.provider` config option
3232
* Add `--exclude` option to the `cache:pool:clear` command
3333
* Add parameters deprecations to the output of `debug:container` command
34+
* Deprecate `AddExpressionLanguageProvidersPass`, use `Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass` instead
35+
* Deprecate `DataCollectorTranslatorPass`, use `Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass` instead
36+
* Deprecate `LoggingTranslatorPass`, use `Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass` instead
37+
* Deprecate `WorkflowGuardListenerPass`, use `Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass` instead
3438

3539
6.3
3640
---

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Reference;
14+
use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass as BaseAddExpressionLanguageProvidersPass;
15+
16+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', AddExpressionLanguageProvidersPass::class, BaseAddExpressionLanguageProvidersPass::class);
1717

1818
/**
19-
* Registers the expression language providers.
20-
*
21-
* @author Fabien Potencier <fabien@symfony.com>
19+
* @deprecated since Symfony 6.4, use Symfony\Component\Routing\DependencyInjection\AddExpressionLanguageProvidersPass instead.
2220
*/
23-
class AddExpressionLanguageProvidersPass implements CompilerPassInterface
21+
class AddExpressionLanguageProvidersPass extends BaseAddExpressionLanguageProvidersPass
2422
{
25-
/**
26-
* @return void
27-
*/
28-
public function process(ContainerBuilder $container)
29-
{
30-
// routing
31-
if ($container->has('router.default')) {
32-
$definition = $container->findDefinition('router.default');
33-
foreach ($container->findTaggedServiceIds('routing.expression_language_provider', true) as $id => $attributes) {
34-
$definition->addMethodCall('addExpressionLanguageProvider', [new Reference($id)]);
35-
}
36-
}
37-
}
3823
}

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

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\Translation\TranslatorBagInterface;
14+
use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass as BaseDataCollectorTranslatorPass;
15+
16+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', DataCollectorTranslatorPass::class, BaseDataCollectorTranslatorPass::class);
1717

1818
/**
19-
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
19+
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\DataCollectorTranslatorPass instead.
2020
*/
21-
class DataCollectorTranslatorPass implements CompilerPassInterface
21+
class DataCollectorTranslatorPass extends BaseDataCollectorTranslatorPass
2222
{
23-
/**
24-
* @return void
25-
*/
26-
public function process(ContainerBuilder $container)
27-
{
28-
if (!$container->has('translator')) {
29-
return;
30-
}
31-
32-
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
33-
34-
if (!is_subclass_of($translatorClass, TranslatorBagInterface::class)) {
35-
$container->removeDefinition('translator.data_collector');
36-
$container->removeDefinition('data_collector.translation');
37-
}
38-
}
3923
}

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

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

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;
14+
use Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass as BaseLoggingTranslatorPass;
15+
16+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', LoggingTranslatorPass::class, BaseLoggingTranslatorPass::class);
1917

2018
/**
21-
* @author Abdellatif Ait boudad <a.aitboudad@gmail.com>
19+
* @deprecated since Symfony 6.4, use Symfony\Component\Translation\DependencyInjection\LoggingTranslatorPass instead.
2220
*/
23-
class LoggingTranslatorPass implements CompilerPassInterface
21+
class LoggingTranslatorPass extends BaseLoggingTranslatorPass
2422
{
25-
/**
26-
* @return void
27-
*/
28-
public function process(ContainerBuilder $container)
29-
{
30-
if (!$container->hasAlias('logger') || !$container->hasAlias('translator')) {
31-
return;
32-
}
33-
34-
if ($container->hasParameter('translator.logging') && $container->getParameter('translator.logging')) {
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-
if ($r->isSubclassOf(TranslatorInterface::class) && $r->isSubclassOf(TranslatorBagInterface::class)) {
43-
$container->getDefinition('translator.logging')->setDecoratedService('translator');
44-
$warmer = $container->getDefinition('translation.warmer');
45-
$subscriberAttributes = $warmer->getTag('container.service_subscriber');
46-
$warmer->clearTag('container.service_subscriber');
47-
48-
foreach ($subscriberAttributes as $k => $v) {
49-
if ((!isset($v['id']) || 'translator' !== $v['id']) && (!isset($v['key']) || 'translator' !== $v['key'])) {
50-
$warmer->addTag('container.service_subscriber', $v);
51-
}
52-
}
53-
$warmer->addTag('container.service_subscriber', ['key' => 'translator', 'id' => 'translator.logging.inner']);
54-
}
55-
}
56-
}
5723
}

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

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,13 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Exception\LogicException;
14+
use Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass as BaseWorkflowGuardListenerPass;
15+
16+
trigger_deprecation('symfony/framework-bundle', '6.4', 'The "%s" class is deprecated, use "%s" instead.', WorkflowGuardListenerPass::class, BaseWorkflowGuardListenerPass::class);
1717

1818
/**
19-
* @author Christian Flothmann <christian.flothmann@sensiolabs.de>
20-
* @author Grégoire Pineau <lyrixx@lyrixx.info>
19+
* @deprecated since Symfony 6.4, use Symfony\Component\Workflow\DependencyInjection\WorkflowGuardListenerPass instead.
2120
*/
22-
class WorkflowGuardListenerPass implements CompilerPassInterface
21+
class WorkflowGuardListenerPass extends BaseWorkflowGuardListenerPass
2322
{
24-
/**
25-
* @return void
26-
*/
27-
public function process(ContainerBuilder $container)
28-
{
29-
if (!$container->hasParameter('workflow.has_guard_listeners')) {
30-
return;
31-
}
32-
33-
$container->getParameterBag()->remove('workflow.has_guard_listeners');
34-
35-
$servicesNeeded = [
36-
'security.token_storage',
37-
'security.authorization_checker',
38-
'security.authentication.trust_resolver',
39-
'security.role_hierarchy',
40-
];
41-
42-
foreach ($servicesNeeded as $service) {
43-
if (!$container->has($service)) {
44-
throw new LogicException(sprintf('The "%s" service is needed to be able to use the workflow guard listener.', $service));
45-
}
46-
}
47-
}
4823
}

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
@@ -8,6 +8,7 @@ CHANGELOG
88
* Add native return type to `AnnotationClassLoader::setResolver()`
99
* Deprecate Doctrine annotations support in favor of native attributes
1010
* Change the constructor signature of `AnnotationClassLoader` to `__construct(?string $env = null)`, passing an annotation reader as first argument is deprecated
11+
* Add `AddExpressionLanguageProvidersPass` (moved from `FrameworkBundle`)
1112

1213
6.2
1314
---
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
/**
26+
* @return void
27+
*/
28+
public function process(ContainerBuilder $container)
29+
{
30+
// routing
31+
if ($container->has('router.default')) {
32+
$definition = $container->findDefinition('router.default');
33+
foreach ($container->findTaggedServiceIds('routing.expression_language_provider', true) as $id => $attributes) {
34+
$definition->addMethodCall('addExpressionLanguageProvider', [new Reference($id)]);
35+
}
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)