Skip to content

[FrameworkBundle] remove translator helper if Translator is disabled #22006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function load(array $configs, ContainerBuilder $container)
$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
Expand Down Expand Up @@ -752,6 +753,10 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
} else {
$container->removeDefinition('templating.helper.assets');
}

if (!$this->translationConfigEnabled) {
$container->removeDefinition('templating.helper.translator');
}
}
}

Expand Down Expand Up @@ -847,8 +852,6 @@ private function registerTranslatorConfiguration(array $config, ContainerBuilder

$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');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', array(
'translator' => false,
'templating' => array(
'engines' => array('php'),
),
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

$container->loadFromExtension('framework', array(
'translator' => true,
'templating' => array(
'engines' => array('php'),
),
));
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:translator enabled="false" />
<framework:templating>
<framework:engine>php</framework:engine>
</framework:templating>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:framework="http://symfony.com/schema/dic/symfony"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">

<framework:config>
<framework:translator enabled="true" />
<framework:templating>
<framework:engine>php</framework:engine>
</framework:templating>
</framework:config>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
translator: false
templating:
engines: [php]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
translator: true
templating:
engines: [php]
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,20 @@ public function testTranslatorMultipleFallbacks()
$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
*/
Expand Down