Parcourir la source

[DependencyInjection] added the possibility to pass the type of compiler pass in ContainerBuilder::addCompilerPAss

Fabien Potencier il y a 14 ans
Parent
commit
612dce873b

+ 2 - 3
src/Symfony/Bundle/DoctrineBundle/DoctrineBundle.php

@@ -29,8 +29,7 @@ class DoctrineBundle extends Bundle
     {
         parent::registerExtensions($container);
 
-        $passConfig = $container->getCompilerPassConfig();
-        $passConfig->addPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
-        $passConfig->addPass(new CreateProxyDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING);
+        $container->addCompilerPass(new RegisterEventListenersAndSubscribersPass(), PassConfig::TYPE_BEFORE_OPTIMIZATION);
+        $container->addCompilerPass(new CreateProxyDirectoryPass(), PassConfig::TYPE_BEFORE_REMOVING);
     }
 }

+ 3 - 2
src/Symfony/Component/DependencyInjection/Compiler/Compiler.php

@@ -3,6 +3,7 @@
 namespace Symfony\Component\DependencyInjection\Compiler;
 
 use Symfony\Component\DependencyInjection\ContainerBuilder;
+use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 
 /**
  * This class is used to remove circular dependencies between individual passes.
@@ -34,9 +35,9 @@ class Compiler
         return $this->serviceReferenceGraph;
     }
 
-    public function addPass(CompilerPassInterface $pass)
+    public function addPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
     {
-        $this->passConfig->addPass($pass);
+        $this->passConfig->addPass($pass, $type);
     }
 
     public function addLogMessage($string)

+ 4 - 3
src/Symfony/Component/DependencyInjection/ContainerBuilder.php

@@ -4,6 +4,7 @@ namespace Symfony\Component\DependencyInjection;
 
 use Symfony\Component\DependencyInjection\Compiler\Compiler;
 use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
+use Symfony\Component\DependencyInjection\Compiler\PassConfig;
 use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
 use Symfony\Component\DependencyInjection\InterfaceInjector;
 use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -148,11 +149,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
      * Adds a compiler pass at the end of the current passes
      *
      * @param CompilerPassInterface $pass
-     * @return void
+     * @param string                $type
      */
-    public function addCompilerPass(CompilerPassInterface $pass)
+    public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION)
     {
-        $this->compiler->addPass($pass);
+        $this->compiler->addPass($pass, $type);
 
         $this->addObjectResource($pass);
     }