How to Work with Compiler Passes (Symfony Docs) (original) (raw)

Edit this page

Compiler passes give you an opportunity to manipulate otherservice definitions that have been registered with the service container.

If your compiler pass is relatively small, you can define it inside the application's Kernel class instead of creating aseparate compiler pass class.

To do so, make your kernel implement CompilerPassInterfaceand add the compiler pass code inside the process() method:

If you create separate compiler pass classes, enable them in the build()method of the application kernel:

Working with Compiler Passes in Bundles

If your compiler pass is relatively small, you can add it directly in the main bundle class. To do so, make your bundle implement theCompilerPassInterfaceand place the compiler pass code inside the process() method of the main bundle class:

Alternatively, when using separate compiler pass classes, bundles can enable them in the build() method of their main bundle class:

If you are using custom service tags in a bundle, the convention is to format tag names by starting with the bundle's name in lowercase (using underscores as separators), followed by a dot, and finally the specific tag name. For example, to introduce a "transport" tag in your AcmeMailerBundle, you would name it acme_mailer.transport.

This work, including the code samples, is licensed under aCreative Commons BY-SA 3.0 license.