Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
bug #21637 [FrameworkBundle] remove translation data collector when n…
…ot usable (xabbuh) This PR was merged into the 2.7 branch. Discussion ---------- [FrameworkBundle] remove translation data collector when not usable | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17957 | License | MIT | Doc PR | Commits ------- 303bb73 remove translation data collector when not usable
- Loading branch information
Showing
3 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
...mfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/DataCollectorTranslatorPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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\Bundle\FrameworkBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @author Christian Flothmann <christian.flothmann@sensiolabs.de> | ||
*/ | ||
class DataCollectorTranslatorPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->has('translator')) { | ||
return; | ||
} | ||
|
||
$translatorClass = $container->findDefinition('translator')->getClass(); | ||
|
||
if (!is_subclass_of($translatorClass, 'Symfony\Component\Translation\TranslatorBagInterface')) { | ||
$container->removeDefinition('translator.data_collector'); | ||
$container->removeDefinition('data_collector.translation'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...le/FrameworkBundle/Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?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\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\DataCollectorTranslatorPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\Translation\TranslatorInterface; | ||
|
||
class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
private $container; | ||
private $dataCollectorTranslatorPass; | ||
|
||
protected function setUp() | ||
{ | ||
$this->container = new ContainerBuilder(); | ||
$this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass(); | ||
|
||
$this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator') | ||
->setPublic(false) | ||
->setDecoratedService('translator') | ||
->setArguments(array(new Reference('translator.data_collector.inner'))) | ||
; | ||
|
||
$this->container->register('data_collector.translation', 'Symfony\Component\Translation\DataCollector\TranslationDataCollector') | ||
->setArguments(array(new Reference('translator.data_collector'))) | ||
; | ||
} | ||
|
||
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface() | ||
{ | ||
$this->container->register('translator', 'Symfony\Component\Translation\Translator'); | ||
|
||
$this->dataCollectorTranslatorPass->process($this->container); | ||
|
||
$this->assertTrue($this->container->hasDefinition('translator.data_collector')); | ||
} | ||
|
||
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface() | ||
{ | ||
$this->container->register('translator', 'Symfony\Component\Translation\Translator'); | ||
|
||
$this->dataCollectorTranslatorPass->process($this->container); | ||
|
||
$this->assertTrue($this->container->hasDefinition('data_collector.translation')); | ||
} | ||
|
||
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface() | ||
{ | ||
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'); | ||
|
||
$this->dataCollectorTranslatorPass->process($this->container); | ||
|
||
$this->assertFalse($this->container->hasDefinition('translator.data_collector')); | ||
} | ||
|
||
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface() | ||
{ | ||
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'); | ||
|
||
$this->dataCollectorTranslatorPass->process($this->container); | ||
|
||
$this->assertFalse($this->container->hasDefinition('data_collector.translation')); | ||
} | ||
} | ||
|
||
class TranslatorWithTranslatorBag implements TranslatorInterface | ||
{ | ||
public function trans($id, array $parameters = array(), $domain = null, $locale = null) | ||
{ | ||
} | ||
|
||
public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) | ||
{ | ||
} | ||
|
||
public function setLocale($locale) | ||
{ | ||
} | ||
|
||
public function getLocale() | ||
{ | ||
} | ||
} |