From 25ea510ba4a23238dbc34706d2bed4361df423f8 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 15 Mar 2017 11:56:07 +0100 Subject: [PATCH] remove translator helper if Translator is disabled --- .../DependencyInjection/FrameworkExtension.php | 7 +++++-- .../php/templating_php_translator_disabled.php | 8 ++++++++ .../php/templating_php_translator_enabled.php | 8 ++++++++ .../xml/templating_php_translator_disabled.xml | 14 ++++++++++++++ .../xml/templating_php_translator_enabled.xml | 14 ++++++++++++++ .../yml/templating_php_translator_disabled.yml | 4 ++++ .../yml/templating_php_translator_enabled.yml | 4 ++++ .../DependencyInjection/FrameworkExtensionTest.php | 14 ++++++++++++++ 8 files changed, 71 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_disabled.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_enabled.php create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_disabled.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_enabled.xml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_disabled.yml create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_enabled.yml diff --git a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php index 7a9d77f75f..f69ab0cee7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php +++ b/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php @@ -96,6 +96,7 @@ class FrameworkExtension extends Extension $config = $this->processConfiguration($configuration, $configs); $this->annotationsConfigEnabled = $this->isConfigEnabled($container, $config['annotations']); + $this->translationConfigEnabled = $this->isConfigEnabled($container, $config['translator']); // A translator must always be registered (as support is included by // default in the Form and Validator component). If disabled, an identity @@ -752,6 +753,10 @@ class FrameworkExtension extends Extension } else { $container->removeDefinition('templating.helper.assets'); } + + if (!$this->translationConfigEnabled) { + $container->removeDefinition('templating.helper.translator'); + } } } @@ -847,8 +852,6 @@ class FrameworkExtension extends Extension $loader->load('translation.xml'); - $this->translationConfigEnabled = true; - // Use the "real" translator instead of the identity default $container->setAlias('translator', 'translator.default'); $translator = $container->findDefinition('translator.default'); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_disabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_disabled.php new file mode 100644 index 0000000000..4fb2aec557 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_disabled.php @@ -0,0 +1,8 @@ +loadFromExtension('framework', array( + 'translator' => false, + 'templating' => array( + 'engines' => array('php'), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_enabled.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_enabled.php new file mode 100644 index 0000000000..b8053c853b --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/php/templating_php_translator_enabled.php @@ -0,0 +1,8 @@ +loadFromExtension('framework', array( + 'translator' => true, + 'templating' => array( + 'engines' => array('php'), + ), +)); diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_disabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_disabled.xml new file mode 100644 index 0000000000..72a78aaf0c --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_disabled.xml @@ -0,0 +1,14 @@ + + + + + + + php + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_enabled.xml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_enabled.xml new file mode 100644 index 0000000000..036afa38f7 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/xml/templating_php_translator_enabled.xml @@ -0,0 +1,14 @@ + + + + + + + php + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_disabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_disabled.yml new file mode 100644 index 0000000000..fe0f3e83b5 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_disabled.yml @@ -0,0 +1,4 @@ +framework: + translator: false + templating: + engines: [php] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_enabled.yml b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_enabled.yml new file mode 100644 index 0000000000..0991a2007d --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/Fixtures/yml/templating_php_translator_enabled.yml @@ -0,0 +1,4 @@ +framework: + translator: true + templating: + engines: [php] diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php index 13ff7e08d4..354a69fc63 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php @@ -455,6 +455,20 @@ abstract class FrameworkExtensionTest extends TestCase $this->assertEquals(array('en', 'fr'), $calls[1][1][0]); } + public function testTranslatorHelperIsRegisteredWhenTranslatorIsEnabled() + { + $container = $this->createContainerFromFile('templating_php_translator_enabled'); + + $this->assertTrue($container->has('templating.helper.translator')); + } + + public function testTranslatorHelperIsNotRegisteredWhenTranslatorIsDisabled() + { + $container = $this->createContainerFromFile('templating_php_translator_disabled'); + + $this->assertFalse($container->has('templating.helper.translator')); + } + /** * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException */