From eb77bd90cd94a03aae2674c4fcad02e4ff0a5bab Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 14 Nov 2017 17:43:07 +0100 Subject: [PATCH] More Symfony 4 updates for the service tags article --- service_container/tags.rst | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/service_container/tags.rst b/service_container/tags.rst index 34d6c852de9..19fd550dfdc 100644 --- a/service_container/tags.rst +++ b/service_container/tags.rst @@ -129,11 +129,13 @@ Then, define the chain as a service: .. code-block:: yaml + # config/services.yaml services: App\Mail\TransportChain: ~ .. code-block:: xml + autowire(TransportChain::class); @@ -162,6 +165,7 @@ For example, you may add the following transports as services: .. code-block:: yaml + # config/services.yaml services: Swift_SmtpTransport: arguments: ['%mailer_host%'] @@ -172,6 +176,7 @@ For example, you may add the following transports as services: .. code-block:: xml + register(\Swift_SmtpTransport::class) ->addArgument('%mailer_host%') ->addTag('app.mail_transport'); @@ -245,18 +251,18 @@ Register the Pass with the Container ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ In order to run the compiler pass when the container is compiled, you have to -add the compiler pass to the container in the ``build()`` method of your -bundle:: +add the compiler pass to the container in a :doc:`bundle extension ` +or from your kernel:: - // src/AppBundle.php - - // ... - use Symfony\Component\DependencyInjection\ContainerBuilder; + // src/Kernel.php use App\DependencyInjection\Compiler\MailTransportPass; + // ... - class AppBundle extends Bundle + class Kernel extends Kernel { - public function build(ContainerBuilder $container) + // ... + + protected function build(ContainerBuilder $container) { $container->addCompilerPass(new MailTransportPass()); } @@ -310,6 +316,7 @@ To answer this, change the service declaration: .. code-block:: yaml + # config/services.yaml services: Swift_SmtpTransport: arguments: ['%mailer_host%'] @@ -322,6 +329,7 @@ To answer this, change the service declaration: .. code-block:: xml + register(\Swift_SmtpTransport::class) ->addArgument('%mailer_host%') ->addTag('app.mail_transport', array('alias' => 'foo')); @@ -358,8 +367,8 @@ To answer this, change the service declaration: .. code-block:: yaml + # config/services.yaml services: - # Compact syntax Swift_SendmailTransport: class: \Swift_SendmailTransport