From 1c7b68db0a9488d84b9447627aedf57b151f78ad Mon Sep 17 00:00:00 2001 From: Antoine Lamirault Date: Tue, 27 Dec 2022 22:39:35 +0100 Subject: [PATCH] [DependencyInjection] Add env and param parameters for Autowire attribute --- service_container/autowiring.rst | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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)