Skip to content

Use the new configurator YAML syntax #7203

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

Closed
wants to merge 4 commits into from
Closed
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
21 changes: 19 additions & 2 deletions service_container/configurators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ You can configure the service configurator using the ``configurator`` option:
app.newsletter_manager:
class: AppBundle\Mail\NewsletterManager
arguments: ['@mailer']
configurator: ['@app.email_configurator', configure]
configurator: 'app.email_configurator:configure'
Copy link
Member

Choose a reason for hiding this comment

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

you actually have to use two colons

Copy link
Member Author

Choose a reason for hiding this comment

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

Like this?

configurator: 'app.email_configurator::configure'

Copy link
Member

Choose a reason for hiding this comment

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

yes

Copy link
Member

Choose a reason for hiding this comment

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

@xabbuh that's not true. 2 colons are used when doing a callable referencing a static method (the PHP standard notation Class::staticMethod). The shortcut syntax for service method callables uses a single colon (i.e. something which cannot appear in a valid PHP callable), as done already for the routing configuration.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the confusion Javier. @stof is indeed right.


app.greeting_card_manager:
class: AppBundle\Mail\GreetingCardManager
arguments: ['@mailer']
configurator: ['@app.email_configurator', configure]
configurator: 'app.email_configurator:configure'

.. code-block:: xml

Expand Down Expand Up @@ -186,6 +186,23 @@ You can configure the service configurator using the ``configurator`` option:
->setConfigurator(array(new Reference('app.email_configurator'), 'configure'))
;

.. note::
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't it be versionadded ?


The traditional configurator syntax in YAML files used an array to define
the service id and the method name:

.. code-block:: yaml

app.newsletter_manager:
# new syntax
configurator: 'app.email_configurator:configure'
# old syntax
configurator: ['@app.email_configurator', configure]

.. versionadded:: 3.2
The ``service_id:method_name`` syntax for the YAML configuration format
was introduced in Symfony 3.2.

That's it! When requesting the ``app.newsletter_manager`` or
``app.greeting_card_manager`` service, the created instance will first be
passed to the ``EmailConfigurator::configure()`` method.