diff --git a/service_container/autowiring.rst b/service_container/autowiring.rst index 043f2bd25ed..7e1494657d9 100644 --- a/service_container/autowiring.rst +++ b/service_container/autowiring.rst @@ -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 ` -and even :doc:`complex expressions `:: +The ``#[Autowire]`` attribute can also be used for :ref:`parameters `, +:doc:`complex expressions ` and even :ref:`environment variables `:: // src/Service/MessageGenerator.php namespace App\Service; @@ -580,17 +580,26 @@ and even :doc:`complex expressions `:: #[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)