File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
cookbook/service_container Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change
1
+ How to work with Compiler Passes in Bundles
2
+ ===========================================
3
+
4
+ Compiler passes give you an opportunity to manipulate other service
5
+ definitions that have been registered with the service container. You
6
+ can read about how to create them in the components section ":doc: `/components/dependency_injection/compilation `".
7
+ To register a compiler pass from a bundle you need to add it to the build
8
+ method of the bundle definition class::
9
+
10
+ namespace Acme\MailerBundle;
11
+
12
+ use Symfony\Component\HttpKernel\Bundle\Bundle;
13
+ use Symfony\Component\DependencyInjection\ContainerBuilder;
14
+
15
+ use Acme\MailerBundle\DependencyInjection\Compiler\CustomCompilerPass;
16
+
17
+ class AcmeMailerBundle extends Bundle
18
+ {
19
+ public function build(ContainerBuilder $container)
20
+ {
21
+ parent::build($container);
22
+
23
+ $container->addCompilerPass(new CustomCompilerPass());
24
+ }
25
+ }
26
+
27
+ One of the common tasks for compiler passes is to work with tagged services,
28
+ read more about this in the components section ":doc: `/components/dependency_injection/tags `".
29
+ If you are using custom tags in a bundle then by convention, tag names consist
30
+ of the name of the bundle (lowercase, underscores as separators), followed
31
+ by a dot, and finally the "real" name, so the tag "transport" in the AcmeMailerBundle
32
+ should be: ``acme_mailer.transport ``.
Original file line number Diff line number Diff line change @@ -6,4 +6,4 @@ Service Container
6
6
7
7
event_listener
8
8
scopes
9
- tags
9
+ compiler_passes
You can’t perform that action at this time.
0 commit comments