Skip to content

Commit 0c6bcc6

Browse files
committed
minor #20901 [DependencyInjection] Add when argument to #[AsAlias] (Fan2Shrek)
This PR was merged into the 7.3 branch. Discussion ---------- [DependencyInjection] Add when argument to `#[AsAlias]` Fix #20884 Commits ------- 316c8ac Add when argument to AsAlias
2 parents a5cea71 + 316c8ac commit 0c6bcc6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Diff for: service_container/alias_private.rst

+21
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,27 @@ This means that when using the container directly, you can access the
181181
# ...
182182
app.mailer: '@App\Mail\PhpMailer'
183183
184+
The ``#[AsAlias]`` attribute also support per-environment configuration
185+
via the ``when`` argument::
186+
187+
// src/Mail/PhpMailer.php
188+
namespace App\Mail;
189+
190+
// ...
191+
use Symfony\Component\DependencyInjection\Attribute\AsAlias;
192+
193+
#[AsAlias(id: 'app.mailer', when: 'dev')]
194+
class PhpMailer
195+
{
196+
// ...
197+
}
198+
199+
You can pass either a string or an array of strings to the ``when`` argument.
200+
201+
.. versionadded:: 7.3
202+
203+
The ``when`` argument on the ``#[AsAlias]`` attribute was introduced in Symfony 7.3.
204+
184205
.. tip::
185206

186207
When using ``#[AsAlias]`` attribute, you may omit passing ``id`` argument

0 commit comments

Comments
 (0)