Skip to content

[DependencyInjection] Add env and param parameters for Autowire attribute #17626

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
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
17 changes: 13 additions & 4 deletions service_container/autowiring.rst
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,8 @@ logic about those arguments::

The ``#[Autowire]`` attribute was introduced in Symfony 6.1.

The ``#[Autowire]`` attribute can also be used for :ref:`parameters <service-parameters>`
and even :doc:`complex expressions </service_container/expression_language>`::
The ``#[Autowire]`` attribute can also be used for :ref:`parameters <service-parameters>`,
:doc:`complex expressions </service_container/expression_language>` and even :ref:`environment variables <config-env-vars>`::

// src/Service/MessageGenerator.php
namespace App\Service;
Expand All @@ -580,17 +580,26 @@ and even :doc:`complex expressions </service_container/expression_language>`::
#[Autowire('%kernel.project_dir%/data')]
string $dataDir,

#[Autowire('%kernel.debug%')]
// or use argument "param"
#[Autowire(param: 'kernel.debug')]
bool $debugMode,

// and expressions
// expressions
#[Autowire(expression: 'service("App\\Mail\\MailerConfiguration").getMailerMethod()')]
string $mailerMethod

// environment variable
#[Autowire(env: 'SOME_ENV_VAR')]
string $senderName
) {
}
// ...
}

.. versionadded:: 6.3

The ``param`` and ``env`` arguments were introduced in Symfony 6.3.

.. _autowiring-calls:

Autowiring other Methods (e.g. Setters and Public Typed Properties)
Expand Down