Skip to content

Commit 800e3cb

Browse files
committed
feature #22619 [FrameworkBundle][Translation] Move translation compiler pass (lepiaf)
This PR was merged into the 3.4 branch. Discussion ---------- [FrameworkBundle][Translation] Move translation compiler pass | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | part of #21284 | License | MIT | Doc PR | n/a move TranslationDumperPass, TranslationExtractorPass, TranslatorPass to Translation component. Commits ------- 74c951fa04 [FrameworkBundle][Translation] Move translation compiler pass
2 parents 6f50bf4 + a087436 commit 800e3cb

File tree

8 files changed

+40
-83
lines changed

8 files changed

+40
-83
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ CHANGELOG
1212
* Deprecated the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
1313
* Deprecated `AddCacheClearerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` instead.
1414
* Deprecated `AddCacheWarmerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` instead.
15+
* Deprecated `TranslationDumperPass`, use
16+
`Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` instead
17+
* Deprecated `TranslationExtractorPass`, use
18+
`Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass` instead
19+
* Deprecated `TranslatorPass`, use
20+
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` instead
1521

1622
3.3.0
1723
-----

DependencyInjection/Compiler/TranslationDumperPass.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,15 @@
1111

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

14-
use Symfony\Component\DependencyInjection\Reference;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass instead.', TranslationDumperPass::class), E_USER_DEPRECATED);
15+
16+
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass as BaseTranslationDumperPass;
1717

1818
/**
1919
* Adds tagged translation.formatter services to translation writer.
20+
*
21+
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslationDumperPass instead}.
2022
*/
21-
class TranslationDumperPass implements CompilerPassInterface
23+
class TranslationDumperPass extends BaseTranslationDumperPass
2224
{
23-
public function process(ContainerBuilder $container)
24-
{
25-
if (!$container->hasDefinition('translation.writer')) {
26-
return;
27-
}
28-
29-
$definition = $container->getDefinition('translation.writer');
30-
31-
foreach ($container->findTaggedServiceIds('translation.dumper', true) as $id => $attributes) {
32-
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
33-
}
34-
}
3525
}

DependencyInjection/Compiler/TranslationExtractorPass.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,15 @@
1111

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

14-
use Symfony\Component\DependencyInjection\Reference;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass instead.', TranslationExtractorPass::class), E_USER_DEPRECATED);
15+
16+
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass as BaseTranslationExtractorPass;
1817

1918
/**
20-
* Adds tagged translation.extractor services to translation extractor.
19+
* Adds tagged translation.formatter services to translation writer.
20+
*
21+
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslationDumperPass instead}.
2122
*/
22-
class TranslationExtractorPass implements CompilerPassInterface
23+
class TranslationExtractorPass extends BaseTranslationExtractorPass
2324
{
24-
public function process(ContainerBuilder $container)
25-
{
26-
if (!$container->hasDefinition('translation.extractor')) {
27-
return;
28-
}
29-
30-
$definition = $container->getDefinition('translation.extractor');
31-
32-
foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
33-
if (!isset($attributes[0]['alias'])) {
34-
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
35-
}
36-
37-
$definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
38-
}
39-
}
4025
}

DependencyInjection/Compiler/TranslatorPass.php

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,15 @@
1111

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

14-
use Symfony\Component\DependencyInjection\Reference;
15-
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17-
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
14+
@trigger_error(sprintf('The %s class is deprecated since version 3.4 and will be removed in 4.0. Use Symfony\Component\Translation\DependencyInjection\TranslatorPass instead.', TranslatorPass::class), E_USER_DEPRECATED);
1815

19-
class TranslatorPass implements CompilerPassInterface
20-
{
21-
public function process(ContainerBuilder $container)
22-
{
23-
if (!$container->hasDefinition('translator.default')) {
24-
return;
25-
}
26-
27-
$loaders = array();
28-
$loaderRefs = array();
29-
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
30-
$loaderRefs[$id] = new Reference($id);
31-
$loaders[$id][] = $attributes[0]['alias'];
32-
if (isset($attributes[0]['legacy-alias'])) {
33-
$loaders[$id][] = $attributes[0]['legacy-alias'];
34-
}
35-
}
36-
37-
if ($container->hasDefinition('translation.loader')) {
38-
$definition = $container->getDefinition('translation.loader');
39-
foreach ($loaders as $id => $formats) {
40-
foreach ($formats as $format) {
41-
$definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
42-
}
43-
}
44-
}
16+
use Symfony\Component\Translation\DependencyInjection\TranslatorPass as BaseTranslatorPass;
4517

46-
$container
47-
->findDefinition('translator.default')
48-
->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))
49-
->replaceArgument(3, $loaders)
50-
;
51-
}
18+
/**
19+
* Adds tagged translation.formatter services to translation writer.
20+
*
21+
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslatorPass instead}.
22+
*/
23+
class TranslatorPass extends BaseTranslatorPass
24+
{
5225
}

FrameworkBundle.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@
1919
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
2020
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
2121
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
22-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
2322
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
2423
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
2524
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
26-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
27-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
2825
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2926
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
3027
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
@@ -45,6 +42,9 @@
4542
use Symfony\Component\HttpFoundation\Request;
4643
use Symfony\Component\HttpKernel\Bundle\Bundle;
4744
use Symfony\Component\Config\Resource\ClassExistenceResource;
45+
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
46+
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
47+
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
4848
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
4949
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
5050
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass;
@@ -93,13 +93,13 @@ public function build(ContainerBuilder $container)
9393
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
9494
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
9595
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
96-
$container->addCompilerPass(new TranslatorPass());
96+
$this->addCompilerPassIfExists($container, TranslatorPass::class);
9797
$container->addCompilerPass(new LoggingTranslatorPass());
9898
$container->addCompilerPass(new AddCacheWarmerPass());
9999
$container->addCompilerPass(new AddCacheClearerPass());
100100
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
101-
$container->addCompilerPass(new TranslationExtractorPass());
102-
$container->addCompilerPass(new TranslationDumperPass());
101+
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
102+
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
103103
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
104104
$this->addCompilerPassIfExists($container, SerializerPass::class);
105105
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);

Tests/DependencyInjection/Compiler/TranslatorPassTest.php

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

21+
/**
22+
* @group legacy
23+
*/
2124
class TranslatorPassTest extends TestCase
2225
{
2326
public function testValidCollector()

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
1313

1414
use Doctrine\Common\Annotations\Annotation;
15-
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
1615
use Symfony\Bundle\FullStack;
1716
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
1817
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
@@ -41,6 +40,7 @@
4140
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
4241
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
4342
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
43+
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
4444
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
4545

4646
abstract class FrameworkExtensionTest extends TestCase

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"symfony/security-csrf": "~2.8|~3.0|~4.0",
4848
"symfony/serializer": "~3.3|~4.0",
4949
"symfony/stopwatch": "~2.8|~3.0|~4.0",
50-
"symfony/translation": "~3.2|~4.0",
50+
"symfony/translation": "~3.4|~4.0",
5151
"symfony/templating": "~2.8|~3.0|~4.0",
5252
"symfony/validator": "~3.4|~4.0",
5353
"symfony/var-dumper": "~3.3|~4.0",
@@ -69,7 +69,7 @@
6969
"symfony/http-kernel": "<3.4",
7070
"symfony/property-info": "<3.3",
7171
"symfony/serializer": "<3.3",
72-
"symfony/translation": "<3.2",
72+
"symfony/translation": "<3.4",
7373
"symfony/validator": "<3.4",
7474
"symfony/workflow": "<3.3"
7575
},

0 commit comments

Comments
 (0)