Skip to content

More Symfony 4 updates for the service tags article #8655

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,13 @@ Then, define the chain as a service:

.. code-block:: yaml

# config/services.yaml
services:
App\Mail\TransportChain: ~

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -147,6 +149,7 @@ Then, define the chain as a service:

.. code-block:: php

// config/services.php
use App\Mail\TransportChain;

$container->autowire(TransportChain::class);
Expand All @@ -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%']
Expand All @@ -172,6 +176,7 @@ For example, you may add the following transports as services:

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -193,6 +198,7 @@ For example, you may add the following transports as services:

.. code-block:: php

// config/services.php
$container->register(\Swift_SmtpTransport::class)
->addArgument('%mailer_host%')
->addTag('app.mail_transport');
Expand Down Expand Up @@ -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 </bundles/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
Copy link
Member

@yceruto yceruto Nov 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

namespace App; + use ... as BaseKernel; + ... extends BaseKernel?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 1a3be43

{
public function build(ContainerBuilder $container)
// ...

protected function build(ContainerBuilder $container)
{
$container->addCompilerPass(new MailTransportPass());
}
Expand Down Expand Up @@ -310,6 +316,7 @@ To answer this, change the service declaration:

.. code-block:: yaml

# config/services.yaml
services:
Swift_SmtpTransport:
arguments: ['%mailer_host%']
Expand All @@ -322,6 +329,7 @@ To answer this, change the service declaration:

.. code-block:: xml

<!-- config/services.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -343,6 +351,7 @@ To answer this, change the service declaration:

.. code-block:: php

// config/services.php
$container->register(\Swift_SmtpTransport::class)
->addArgument('%mailer_host%')
->addTag('app.mail_transport', array('alias' => 'foo'));
Expand All @@ -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
Expand Down