Explorar el Código

[FrameworkBundle] added a compiler pass for translation loaders

Fabien Potencier hace 14 años
padre
commit
e0050dfc8f

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

@@ -0,0 +1,22 @@
+<?php
+
+namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+class TranslatorPass implements CompilerPassInterface
+{
+    public function process(ContainerBuilder $container)
+    {
+        if (!$container->hasDefinition('translator')) {
+            return;
+        }
+
+        $loaders = array();
+        foreach ($container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
+            $loaders[$id] = $attributes[0]['alias'];
+        }
+        $container->setParameter('translation.loaders', $loaders);
+    }
+}

+ 2 - 0
src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

@@ -10,6 +10,7 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConverterManager
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\RoutingResolverPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ProfilerPass;
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddClassesToCachePass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TranslatorPass;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 use Symfony\Component\HttpKernel\Bundle\Bundle;
@@ -72,5 +73,6 @@ class FrameworkBundle extends Bundle
         $container->addCompilerPass(new TemplatingPass());
         $container->addCompilerPass(new AddConstraintValidatorsPass());
         $container->addCompilerPass(new AddClassesToCachePass());
+        $container->addCompilerPass(new TranslatorPass());
     }
 }

+ 2 - 2
src/Symfony/Bundle/FrameworkBundle/Translation/Translator.php

@@ -103,8 +103,8 @@ class Translator extends BaseTranslator
 
     protected function initialize()
     {
-        foreach ($this->container->findTaggedServiceIds('translation.loader') as $id => $attributes) {
-            $this->addLoader($attributes[0]['alias'], $this->container->get($id));
+        foreach ($this->container->getParameter('translation.loaders') as $id => $alias) {
+            $this->addLoader($alias, $this->container->get($id));
         }
 
         foreach ($this->container->getParameter('translation.resources') as $resource) {