Skip to content

Commit fdaf8bb

Browse files
Added cookbook on differences whne using compiler passes in the framework
1 parent ecbef63 commit fdaf8bb

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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``.

cookbook/service_container/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Service Container
66

77
event_listener
88
scopes
9-
tags
9+
compiler_passes

0 commit comments

Comments
 (0)