Skip to content

Commit abb21f2

Browse files
committed
remove translator helper if Translator is disabled
1 parent 47d1e4e commit abb21f2

8 files changed

+71
-2
lines changed

DependencyInjection/FrameworkExtension.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public function load(array $configs, ContainerBuilder $container)
9696
$config = $this->processConfiguration($configuration, $configs);
9797

9898
$this->annotationsConfigEnabled = $this->isConfigEnabled($container, $config['annotations']);
99+
$this->translationConfigEnabled = $this->isConfigEnabled($container, $config['translator']);
99100

100101
// A translator must always be registered (as support is included by
101102
// default in the Form and Validator component). If disabled, an identity
@@ -752,6 +753,10 @@ private function registerTemplatingConfiguration(array $config, ContainerBuilder
752753
} else {
753754
$container->removeDefinition('templating.helper.assets');
754755
}
756+
757+
if (!$this->translationConfigEnabled) {
758+
$container->removeDefinition('templating.helper.translator');
759+
}
755760
}
756761
}
757762

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

848853
$loader->load('translation.xml');
849854

850-
$this->translationConfigEnabled = true;
851-
852855
// Use the "real" translator instead of the identity default
853856
$container->setAlias('translator', 'translator.default');
854857
$translator = $container->findDefinition('translator.default');
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'translator' => false,
5+
'templating' => array(
6+
'engines' => array('php'),
7+
),
8+
));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', array(
4+
'translator' => true,
5+
'templating' => array(
6+
'engines' => array('php'),
7+
),
8+
));
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:translator enabled="false" />
10+
<framework:templating>
11+
<framework:engine>php</framework:engine>
12+
</framework:templating>
13+
</framework:config>
14+
</container>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:translator enabled="true" />
10+
<framework:templating>
11+
<framework:engine>php</framework:engine>
12+
</framework:templating>
13+
</framework:config>
14+
</container>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
translator: false
3+
templating:
4+
engines: [php]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework:
2+
translator: true
3+
templating:
4+
engines: [php]

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,20 @@ public function testTranslatorMultipleFallbacks()
455455
$this->assertEquals(array('en', 'fr'), $calls[1][1][0]);
456456
}
457457

458+
public function testTranslatorHelperIsRegisteredWhenTranslatorIsEnabled()
459+
{
460+
$container = $this->createContainerFromFile('templating_php_translator_enabled');
461+
462+
$this->assertTrue($container->has('templating.helper.translator'));
463+
}
464+
465+
public function testTranslatorHelperIsNotRegisteredWhenTranslatorIsDisabled()
466+
{
467+
$container = $this->createContainerFromFile('templating_php_translator_disabled');
468+
469+
$this->assertFalse($container->has('templating.helper.translator'));
470+
}
471+
458472
/**
459473
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException
460474
*/

0 commit comments

Comments
 (0)