Symfony\Component\DependencyInjection\ContainerBuilder::addCompilerPass PHP Method

addCompilerPass() public method

Adds a compiler pass.
public addCompilerPass ( Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface $pass, string $type = PassConfig::TYPE_BEFORE_OPTIMIZATION ) : ContainerBuilder
$pass Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface A compiler pass
$type string The type of compiler pass
return ContainerBuilder The current instance
    public function addCompilerPass(CompilerPassInterface $pass, $type = PassConfig::TYPE_BEFORE_OPTIMIZATION/*, $priority = 0*/)
    {
        if (func_num_args() >= 3) {
            $priority = func_get_arg(2);
        } else {
            if (__CLASS__ !== get_class($this)) {
                $r = new \ReflectionMethod($this, __FUNCTION__);
                if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
                    @trigger_error(sprintf('Method %s() will have a third `$priority = 0` argument in version 4.0. Not defining it is deprecated since 3.2.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
                }
            }

            $priority = 0;
        }

        $this->getCompiler()->addPass($pass, $type, $priority);

        $this->addObjectResource($pass);

        return $this;
    }

Usage Example

    /**
     * {@inheritdoc}
     */
    public function build(ContainerBuilder $container)
    {
        $container->addCompilerPass(new DelegatingLoaderCloningCompilerPass());
        $routingResourcesProvider = new ExtensionPoint('modera_routing.routing_resources');
        $docs = <<<TEXT
This extension points make it possible for bundles to dynamically contribute routing resources so Symfony can detect them,
this way when a new bundle is added then you don't need to update root routing.yml file every time.
This how a sample contribution could look like:

use Sli\\ExpanderBundle\\Ext\\ContributorInterface;

class RoutingResourcesProvider implements ContributorInterface
{
    /**
     * @inheritDoc
     */
    public function getItems()
    {
        return array(
            '@ModeraBackendLanguagesBundle/Resources/config/routing.yml'
        );
    }
}
TEXT;
        $routingResourcesProvider->setDetailedDescription($docs);
        $routingResourcesProvider->setDescription('Allows to dynamically add routing files.');
        $container->addCompilerPass($routingResourcesProvider->createCompilerPass());
    }
All Usage Examples Of Symfony\Component\DependencyInjection\ContainerBuilder::addCompilerPass