Bladeren bron

[FrameworkBundle] Moved the adding of Converter tags to a CompilerPass by suggestion of schmittjoh.

Henrik Bjørnskov 14 jaren geleden
bovenliggende
commit
3516a043bc

+ 1 - 7
src/Symfony/Bundle/FrameworkBundle/Controller/ParamConverterListener.php

@@ -26,15 +26,9 @@ class ParamConverterListener
 
     /**
      * @param ConverterManager   $manager
-     * @param ContainerInterface $container
      */
-    public function __construct(ConverterManager $manager, ContainerInterface $container)
+    public function __construct(ConverterManager $manager)
     {
-        foreach ($container->findTaggedServiceIds('request.param_converter') as $id => $attributes) {
-            $priority = isset($attributes['priority']) ? (integer) $attributes['priority'] : 0;
-            $manager->add($container->get($id), $priority);
-        }
-
         $this->manager = $manager;
     }
 

+ 47 - 0
src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/ConverterManagerPass.php

@@ -0,0 +1,47 @@
+<?php
+
+namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
+
+use Symfony\Component\DependencyInjection\Reference;
+use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+
+/*
+ * This file is part of the Symfony package.
+ *
+ * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+/**
+ * Adds tagged request.param_converter to request.param_converter.manager service
+ *
+ * @author Henrik Bjornskov <hb@peytz.dk>
+ */
+class ConverterManagerPass implements CompilerPassInterface
+{
+    /**
+     * Adds ParamConverters to ConverterManager
+     *
+     * @param ContainerBuilder $container
+     */
+    public function process(ContainerBuilder $container)
+    {
+        if (false === $container->hasDefinition('request.param_converter.manager')) {
+            return;
+        }
+
+        $definition = $container->getDefinition('request.param_converter.manager');
+
+        foreach ($container->findTaggedServiceIds('request.param_converter') as $serviceId => $attributes) {
+            $priority = 0;
+            if (isset($attributes['priority'])) {
+                $priority = (integer) $attributes['priority'];
+            }
+
+            $definition->addMethodCall('add', array(new Reference($serviceId), $priority));
+        }
+    }
+}

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

@@ -3,6 +3,7 @@
 namespace Symfony\Bundle\FrameworkBundle;
 
 use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddSecurityVotersPass;
+use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConverterManagerPass;
 use Symfony\Component\DependencyInjection\ContainerBuilder;
 use Symfony\Component\HttpKernel\Bundle\Bundle;
 use Symfony\Component\Form\FormConfiguration;
@@ -42,5 +43,6 @@ class FrameworkBundle extends Bundle
         parent::registerExtensions($container);
 
         $container->addCompilerPass(new AddSecurityVotersPass());
+        $container->addCompilerPass(new ConverterManagerPass());
     }
 }

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

@@ -17,7 +17,6 @@
         <service id="request.param_converter.listener" class="%request.param_converter.listener.class%">
             <tag name="kernel.listener" />
             <argument type="service" id="request.param_converter.manager" />
-            <argument type="service" id="service_container" />
         </service>
     </services>
 </container>