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
This commit is contained in:
commit
bfaf8a0fdc
@ -45,7 +45,19 @@ FrameworkBundle
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass`
|
||||
class has been deprecated and will be removed in 4.0. Use the
|
||||
`Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.
|
||||
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass`
|
||||
class has been deprecated and will be removed in 4.0. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass`
|
||||
class has been deprecated and will be removed in 4.0. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass` class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass`
|
||||
class has been deprecated and will be removed in 4.0. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
|
||||
|
||||
Process
|
||||
-------
|
||||
|
||||
|
@ -354,6 +354,18 @@ FrameworkBundle
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddCacheWarmerPass` class has been removed.
|
||||
Use the `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass`
|
||||
class has been removed. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass`
|
||||
class has been removed. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass` class instead.
|
||||
|
||||
* The `Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass`
|
||||
class has been removed. Use the
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` class instead.
|
||||
|
||||
HttpFoundation
|
||||
--------------
|
||||
|
||||
|
@ -12,6 +12,12 @@ CHANGELOG
|
||||
* Deprecated the `KernelTestCase::getPhpUnitXmlDir()` and `KernelTestCase::getPhpUnitCliConfigArgument()` methods.
|
||||
* Deprecated `AddCacheClearerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheClearerPass` instead.
|
||||
* Deprecated `AddCacheWarmerPass`, use `Symfony\Component\HttpKernel\DependencyInjection\AddCacheWarmerPass` instead.
|
||||
* Deprecated `TranslationDumperPass`, use
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationDumperPass` instead
|
||||
* Deprecated `TranslationExtractorPass`, use
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass` instead
|
||||
* Deprecated `TranslatorPass`, use
|
||||
`Symfony\Component\Translation\DependencyInjection\TranslatorPass` instead
|
||||
|
||||
3.3.0
|
||||
-----
|
||||
|
@ -11,25 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
@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);
|
||||
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass as BaseTranslationDumperPass;
|
||||
|
||||
/**
|
||||
* Adds tagged translation.formatter services to translation writer.
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslationDumperPass instead}.
|
||||
*/
|
||||
class TranslationDumperPass implements CompilerPassInterface
|
||||
class TranslationDumperPass extends BaseTranslationDumperPass
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('translation.writer')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition('translation.writer');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('translation.dumper', true) as $id => $attributes) {
|
||||
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,30 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
@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);
|
||||
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass as BaseTranslationExtractorPass;
|
||||
|
||||
/**
|
||||
* Adds tagged translation.extractor services to translation extractor.
|
||||
* Adds tagged translation.formatter services to translation writer.
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslationDumperPass instead}.
|
||||
*/
|
||||
class TranslationExtractorPass implements CompilerPassInterface
|
||||
class TranslationExtractorPass extends BaseTranslationExtractorPass
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('translation.extractor')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition('translation.extractor');
|
||||
|
||||
foreach ($container->findTaggedServiceIds('translation.extractor', true) as $id => $attributes) {
|
||||
if (!isset($attributes[0]['alias'])) {
|
||||
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
||||
}
|
||||
|
||||
$definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,42 +11,15 @@
|
||||
|
||||
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
||||
@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);
|
||||
|
||||
class TranslatorPass implements CompilerPassInterface
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass as BaseTranslatorPass;
|
||||
|
||||
/**
|
||||
* Adds tagged translation.formatter services to translation writer.
|
||||
*
|
||||
* @deprecated since version 3.4, to be removed in 4.0. Use {@link BaseTranslatorPass instead}.
|
||||
*/
|
||||
class TranslatorPass extends BaseTranslatorPass
|
||||
{
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition('translator.default')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loaders = array();
|
||||
$loaderRefs = array();
|
||||
foreach ($container->findTaggedServiceIds('translation.loader', true) as $id => $attributes) {
|
||||
$loaderRefs[$id] = new Reference($id);
|
||||
$loaders[$id][] = $attributes[0]['alias'];
|
||||
if (isset($attributes[0]['legacy-alias'])) {
|
||||
$loaders[$id][] = $attributes[0]['legacy-alias'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($container->hasDefinition('translation.loader')) {
|
||||
$definition = $container->getDefinition('translation.loader');
|
||||
foreach ($loaders as $id => $formats) {
|
||||
foreach ($formats as $format) {
|
||||
$definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container
|
||||
->findDefinition('translator.default')
|
||||
->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))
|
||||
->replaceArgument(3, $loaders)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,9 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\CachePoolClearer
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TemplatingPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\LoggingTranslatorPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddExpressionLanguageProvidersPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ContainerBuilderDebugDumpPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationExtractorPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslationDumperPass;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
|
||||
use Symfony\Component\Config\DependencyInjection\ConfigCachePass;
|
||||
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
|
||||
@ -45,6 +42,9 @@ use Symfony\Component\Form\DependencyInjection\FormPass;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
use Symfony\Component\Config\Resource\ClassExistenceResource;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
||||
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
||||
use Symfony\Component\Validator\DependencyInjection\AddValidatorInitializersPass;
|
||||
use Symfony\Component\Workflow\DependencyInjection\ValidateWorkflowsPass;
|
||||
@ -93,13 +93,13 @@ class FrameworkBundle extends Bundle
|
||||
$container->addCompilerPass(new AddAnnotationsCachedReaderPass(), PassConfig::TYPE_BEFORE_REMOVING);
|
||||
$this->addCompilerPassIfExists($container, AddValidatorInitializersPass::class);
|
||||
$this->addCompilerPassIfExists($container, AddConsoleCommandPass::class);
|
||||
$container->addCompilerPass(new TranslatorPass());
|
||||
$this->addCompilerPassIfExists($container, TranslatorPass::class);
|
||||
$container->addCompilerPass(new LoggingTranslatorPass());
|
||||
$container->addCompilerPass(new AddCacheWarmerPass());
|
||||
$container->addCompilerPass(new AddCacheClearerPass());
|
||||
$container->addCompilerPass(new AddExpressionLanguageProvidersPass());
|
||||
$container->addCompilerPass(new TranslationExtractorPass());
|
||||
$container->addCompilerPass(new TranslationDumperPass());
|
||||
$this->addCompilerPassIfExists($container, TranslationExtractorPass::class);
|
||||
$this->addCompilerPassIfExists($container, TranslationDumperPass::class);
|
||||
$container->addCompilerPass(new FragmentRendererPass(), PassConfig::TYPE_AFTER_REMOVING);
|
||||
$this->addCompilerPassIfExists($container, SerializerPass::class);
|
||||
$this->addCompilerPassIfExists($container, PropertyInfoPass::class);
|
||||
|
@ -18,6 +18,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
class TranslatorPassTest extends TestCase
|
||||
{
|
||||
public function testValidCollector()
|
||||
|
@ -12,7 +12,6 @@
|
||||
namespace Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
|
||||
use Symfony\Bundle\FullStack;
|
||||
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddAnnotationsCachedReaderPass;
|
||||
@ -41,6 +40,7 @@ use Symfony\Component\Serializer\Mapping\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Serializer\Normalizer\DataUriNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
use Symfony\Component\Serializer\Normalizer\JsonSerializableNormalizer;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
||||
use Symfony\Component\Validator\DependencyInjection\AddConstraintValidatorsPass;
|
||||
|
||||
abstract class FrameworkExtensionTest extends TestCase
|
||||
|
@ -47,7 +47,7 @@
|
||||
"symfony/security-csrf": "~2.8|~3.0|~4.0",
|
||||
"symfony/serializer": "~3.3|~4.0",
|
||||
"symfony/stopwatch": "~2.8|~3.0|~4.0",
|
||||
"symfony/translation": "~3.2|~4.0",
|
||||
"symfony/translation": "~3.4|~4.0",
|
||||
"symfony/templating": "~2.8|~3.0|~4.0",
|
||||
"symfony/validator": "~3.4|~4.0",
|
||||
"symfony/var-dumper": "~3.3|~4.0",
|
||||
@ -69,7 +69,7 @@
|
||||
"symfony/http-kernel": "<3.4",
|
||||
"symfony/property-info": "<3.3",
|
||||
"symfony/serializer": "<3.3",
|
||||
"symfony/translation": "<3.2",
|
||||
"symfony/translation": "<3.4",
|
||||
"symfony/validator": "<3.4",
|
||||
"symfony/workflow": "<3.3"
|
||||
},
|
||||
|
@ -1,6 +1,13 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
3.4.0
|
||||
-----
|
||||
|
||||
* Added `TranslationDumperPass`
|
||||
* Added `TranslationExtractorPass`
|
||||
* Added `TranslatorPass`
|
||||
|
||||
3.2.0
|
||||
-----
|
||||
|
||||
|
@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
/**
|
||||
* Adds tagged translation.formatter services to translation writer.
|
||||
*/
|
||||
class TranslationDumperPass implements CompilerPassInterface
|
||||
{
|
||||
private $writerServiceId;
|
||||
private $dumperTag;
|
||||
|
||||
public function __construct($writerServiceId = 'translation.writer', $dumperTag = 'translation.dumper')
|
||||
{
|
||||
$this->writerServiceId = $writerServiceId;
|
||||
$this->dumperTag = $dumperTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition($this->writerServiceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition($this->writerServiceId);
|
||||
|
||||
foreach ($container->findTaggedServiceIds($this->dumperTag, true) as $id => $attributes) {
|
||||
$definition->addMethodCall('addDumper', array($attributes[0]['alias'], new Reference($id)));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||
|
||||
/**
|
||||
* Adds tagged translation.extractor services to translation extractor.
|
||||
*/
|
||||
class TranslationExtractorPass implements CompilerPassInterface
|
||||
{
|
||||
private $extractorServiceId;
|
||||
private $extractorTag;
|
||||
|
||||
public function __construct($extractorServiceId = 'translation.extractor', $extractorTag = 'translation.extractor')
|
||||
{
|
||||
$this->extractorServiceId = $extractorServiceId;
|
||||
$this->extractorTag = $extractorTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition($this->extractorServiceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$definition = $container->getDefinition($this->extractorServiceId);
|
||||
|
||||
foreach ($container->findTaggedServiceIds($this->extractorTag, true) as $id => $attributes) {
|
||||
if (!isset($attributes[0]['alias'])) {
|
||||
throw new RuntimeException(sprintf('The alias for the tag "translation.extractor" of service "%s" must be set.', $id));
|
||||
}
|
||||
|
||||
$definition->addMethodCall('addExtractor', array($attributes[0]['alias'], new Reference($id)));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
|
||||
|
||||
class TranslatorPass implements CompilerPassInterface
|
||||
{
|
||||
private $translatorServiceId;
|
||||
private $loaderServiceId;
|
||||
private $loaderTag;
|
||||
|
||||
public function __construct($translatorServiceId = 'translator.default', $loaderServiceId = 'translation.loader', $loaderTag = 'translation.loader')
|
||||
{
|
||||
$this->translatorServiceId = $translatorServiceId;
|
||||
$this->loaderServiceId = $loaderServiceId;
|
||||
$this->loaderTag = $loaderTag;
|
||||
}
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasDefinition($this->translatorServiceId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$loaders = array();
|
||||
$loaderRefs = array();
|
||||
foreach ($container->findTaggedServiceIds($this->loaderTag, true) as $id => $attributes) {
|
||||
$loaderRefs[$id] = new Reference($id);
|
||||
$loaders[$id][] = $attributes[0]['alias'];
|
||||
if (isset($attributes[0]['legacy-alias'])) {
|
||||
$loaders[$id][] = $attributes[0]['legacy-alias'];
|
||||
}
|
||||
}
|
||||
|
||||
if ($container->hasDefinition($this->loaderServiceId)) {
|
||||
$definition = $container->getDefinition($this->loaderServiceId);
|
||||
foreach ($loaders as $id => $formats) {
|
||||
foreach ($formats as $format) {
|
||||
$definition->addMethodCall('addLoader', array($format, $loaderRefs[$id]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$container
|
||||
->findDefinition($this->translatorServiceId)
|
||||
->replaceArgument(0, ServiceLocatorTagPass::register($container, $loaderRefs))
|
||||
->replaceArgument(3, $loaders)
|
||||
;
|
||||
}
|
||||
}
|
@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationDumperPass;
|
||||
|
||||
class TranslationDumperPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock();
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('translation.writer')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('translation.writer')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$valueTaggedServiceIdsFound = array(
|
||||
'foo.id' => array(
|
||||
array('alias' => 'bar.alias'),
|
||||
),
|
||||
);
|
||||
$container->expects($this->once())
|
||||
->method('findTaggedServiceIds')
|
||||
->with('translation.dumper', true)
|
||||
->will($this->returnValue($valueTaggedServiceIdsFound));
|
||||
|
||||
$definition->expects($this->once())->method('addMethodCall')->with('addDumper', array('bar.alias', new Reference('foo.id')));
|
||||
|
||||
$translationDumperPass = new TranslationDumperPass();
|
||||
$translationDumperPass->process($container);
|
||||
}
|
||||
|
||||
public function testProcessNoDefinitionFound()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('translation.writer')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$container->expects($this->never())->method('getDefinition');
|
||||
$container->expects($this->never())->method('findTaggedServiceIds');
|
||||
|
||||
$translationDumperPass = new TranslationDumperPass();
|
||||
$translationDumperPass->process($container);
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;
|
||||
|
||||
class TranslationExtractorPassTest extends TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock();
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('translation.extractor')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('translation.extractor')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$valueTaggedServiceIdsFound = array(
|
||||
'foo.id' => array(
|
||||
array('alias' => 'bar.alias'),
|
||||
),
|
||||
);
|
||||
$container->expects($this->once())
|
||||
->method('findTaggedServiceIds')
|
||||
->with('translation.extractor', true)
|
||||
->will($this->returnValue($valueTaggedServiceIdsFound));
|
||||
|
||||
$definition->expects($this->once())->method('addMethodCall')->with('addExtractor', array('bar.alias', new Reference('foo.id')));
|
||||
|
||||
$translationDumperPass = new TranslationExtractorPass();
|
||||
$translationDumperPass->process($container);
|
||||
}
|
||||
|
||||
public function testProcessNoDefinitionFound()
|
||||
{
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('translation.extractor')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$container->expects($this->never())->method('getDefinition');
|
||||
$container->expects($this->never())->method('findTaggedServiceIds');
|
||||
|
||||
$translationDumperPass = new TranslationExtractorPass();
|
||||
$translationDumperPass->process($container);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||
* @expectedExceptionMessage The alias for the tag "translation.extractor" of service "foo.id" must be set.
|
||||
*/
|
||||
public function testProcessMissingAlias()
|
||||
{
|
||||
$definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->disableOriginalConstructor()->getMock();
|
||||
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->disableOriginalConstructor()->getMock();
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('hasDefinition')
|
||||
->with('translation.extractor')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$container->expects($this->once())
|
||||
->method('getDefinition')
|
||||
->with('translation.extractor')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$valueTaggedServiceIdsFound = array(
|
||||
'foo.id' => array(),
|
||||
);
|
||||
$container->expects($this->once())
|
||||
->method('findTaggedServiceIds')
|
||||
->with('translation.extractor', true)
|
||||
->will($this->returnValue($valueTaggedServiceIdsFound));
|
||||
|
||||
$definition->expects($this->never())->method('addMethodCall');
|
||||
|
||||
$translationDumperPass = new TranslationExtractorPass();
|
||||
$translationDumperPass->process($container);
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Translation\Tests\DependencyInjection;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\Translation\DependencyInjection\TranslatorPass;
|
||||
|
||||
class TranslationPassTest extends TestCase
|
||||
{
|
||||
public function testValidCollector()
|
||||
{
|
||||
$loader = (new Definition())
|
||||
->addTag('translation.loader', array('alias' => 'xliff', 'legacy-alias' => 'xlf'));
|
||||
|
||||
$translator = (new Definition())
|
||||
->setArguments(array(null, null, null, null));
|
||||
|
||||
$container = new ContainerBuilder();
|
||||
$container->setDefinition('translator.default', $translator);
|
||||
$container->setDefinition('translation.loader', $loader);
|
||||
|
||||
$pass = new TranslatorPass();
|
||||
$pass->process($container);
|
||||
|
||||
$expected = (new Definition())
|
||||
->addTag('translation.loader', array('alias' => 'xliff', 'legacy-alias' => 'xlf'))
|
||||
->addMethodCall('addLoader', array('xliff', new Reference('translation.loader')))
|
||||
->addMethodCall('addLoader', array('xlf', new Reference('translation.loader')))
|
||||
;
|
||||
$this->assertEquals($expected, $loader);
|
||||
|
||||
$this->assertSame(array('translation.loader' => array('xliff', 'xlf')), $translator->getArgument(3));
|
||||
|
||||
$expected = array('translation.loader' => new ServiceClosureArgument(new Reference('translation.loader')));
|
||||
$this->assertEquals($expected, $container->getDefinition((string) $translator->getArgument(0))->getArgument(0));
|
||||
}
|
||||
}
|
@ -21,12 +21,14 @@
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/config": "~2.8|~3.0|~4.0",
|
||||
"symfony/dependency-injection": "~3.4|~4.0",
|
||||
"symfony/intl": "^2.8.18|^3.2.5|~4.0",
|
||||
"symfony/yaml": "~3.3|~4.0",
|
||||
"psr/log": "~1.0"
|
||||
},
|
||||
"conflict": {
|
||||
"symfony/config": "<2.8",
|
||||
"symfony/dependency-injection": "<3.4",
|
||||
"symfony/yaml": "<3.3"
|
||||
},
|
||||
"suggest": {
|
||||
|
Reference in New Issue
Block a user