Browse Source

[FrameworkBundle] removed two parameters

Fabien Potencier 14 years ago
parent
commit
3ed0ff7b03

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TranslatorPass.php

@@ -9,7 +9,7 @@ class TranslatorPass implements CompilerPassInterface
 {
     public function process(ContainerBuilder $container)
     {
-        if (!$container->hasDefinition('translator')) {
+        if (!$container->hasDefinition('translator.real')) {
             return;
         }
 
@@ -17,6 +17,6 @@ class TranslatorPass implements CompilerPassInterface
         foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
             $loaders[$id] = $attributes[0]['alias'];
         }
-        $container->setParameter('translation.loaders', $loaders);
+        $container->findDefinition('translator.real')->replaceArgument(2, $loaders);
     }
 }

+ 1 - 2
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

@@ -446,10 +446,9 @@ class FrameworkExtension extends Extension
                     // filename is domain.locale.format
                     list($domain, $locale, $format) = explode('.', $file->getBasename());
 
-                    $resources[] = array($format, (string) $file, $locale, $domain);
+                    $translator->addMethodCall('addResource', array($format, (string) $file, $locale, $domain));
                 }
             }
-            $container->setParameter('translation.resources', $resources);
         }
     }
 

+ 1 - 0
src/Symfony/Bundle/FrameworkBundle/Resources/config/translation.xml

@@ -17,6 +17,7 @@
         <service id="translator.real" class="%translator.class%">
             <argument type="service" id="service_container" />
             <argument type="service" id="translator.selector" />
+            <argument type="collection" /> <!-- translation loaders -->
             <argument type="collection">
                 <argument key="cache_dir">%kernel.cache_dir%/translations</argument>
                 <argument key="debug">%kernel.debug%</argument>

+ 8 - 1
src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

@@ -117,9 +117,16 @@ abstract class FrameworkExtensionTest extends TestCase
         $this->assertTrue($container->hasDefinition('translator.real'), '->registerTranslatorConfiguration() loads translation.xml');
         $this->assertSame($container->getDefinition('translator.real'), $container->getDefinition('translator'), '->registerTranslatorConfiguration() redefines translator service from identity to real translator');
 
+        $resources = array();
+        foreach ($container->getDefinition('translator.real')->getMethodCalls() as $call) {
+            if ('addResource' == $call[0]) {
+                $resources[] = $call[1];
+            }
+        }
+
         $this->assertContains(
             realpath(__DIR__.'/../../Resources/translations/validators.fr.xliff'),
-            array_map(function($resource) { return realpath($resource[1]); }, $container->getParameter('translation.resources')),
+            array_map(function($resource) use ($resources) { return realpath($resource[1]); }, $resources),
             '->registerTranslatorConfiguration() finds FrameworkExtension translation resources'
         );
 

+ 4 - 6
src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php

@@ -28,6 +28,7 @@ class Translator extends BaseTranslator
     protected $container;
     protected $options;
     protected $session;
+    protected $loaderIds;
 
     /**
      * Constructor.
@@ -42,12 +43,13 @@ class Translator extends BaseTranslator
      * @param array              $options   An array of options
      * @param Session            $session   A Session instance
      */
-    public function __construct(ContainerInterface $container, MessageSelector $selector, array $options = array(), Session $session = null)
+    public function __construct(ContainerInterface $container, MessageSelector $selector, $loaderIds = array(), array $options = array(), Session $session = null)
     {
         parent::__construct(null, $selector);
 
         $this->session = $session;
         $this->container = $container;
+        $this->loaderIds = $loaderIds;
 
         $this->options = array(
             'cache_dir' => null,
@@ -111,12 +113,8 @@ class Translator extends BaseTranslator
 
     protected function initialize()
     {
-        foreach ($this->container->getParameter('translation.loaders') as $id => $alias) {
+        foreach ($this->loaderIds as $id => $alias) {
             $this->addLoader($alias, $this->container->get($id));
         }
-
-        foreach ($this->container->getParameter('translation.resources') as $resource) {
-            $this->addResource($resource[0], $resource[1], $resource[2], $resource[3]);
-        }
     }
 }