概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:49:14 | 139 次阅读 | 评论: 0 | 来源: 网络整理

Compiler passes give you an opportunity to manipulate other service definitions that have been registered with the service container. You can read about how to create them in the components section “Compiling the Container”. To register a compiler pass from a bundle you need to add it to the build method of the bundle definition class:

// src/Acme/MailerBundle/AcmeMailerBundle.php
namespace AcmeMailerBundle;

use SymfonyComponentHttpKernelBundleBundle;
use SymfonyComponentDependencyInjectionContainerBuilder;

use AcmeMailerBundleDependencyInjectionCompilerCustomCompilerPass;

class AcmeMailerBundle extends Bundle
{
    public function build(ContainerBuilder $container)
    {
        parent::build($container);

        $container->addCompilerPass(new CustomCompilerPass());
    }
}

One of the most common use-cases of compiler passes is to work with tagged services (read more about tags in the components section “Working with Tagged Services”). If you are using custom tags in a bundle then by convention, tag names consist of the name of the bundle (lowercase, underscores as separators), followed by a dot, and finally the “real” name. For example, if you want to introduce some sort of “transport” tag in your AcmeMailerBundle, you should call it acme_mailer.transport.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务