@@ -95,6 +95,20 @@ services.
9595
9696.. configuration-block ::
9797
98+ .. code-block :: php-attributes
99+
100+ // src/Mail/PhpMailer.php
101+ namespace App\Mail;
102+
103+ // ...
104+ use Symfony\Component\DependencyInjection\Attribute\AsAlias;
105+
106+ #[AsAlias(id: 'app.mailer', public: true)]
107+ class PhpMailer
108+ {
109+ // ...
110+ }
111+
98112 .. code-block :: yaml
99113
100114 # config/services.yaml
@@ -139,6 +153,10 @@ services.
139153 $services->alias('app.mailer', PhpMailer::class);
140154 };
141155
156+ .. versionadded :: 6.3
157+
158+ The ``#[AsAlias] `` attribute was introduced in Symfony 6.3.
159+
142160This means that when using the container directly, you can access the
143161``PhpMailer `` service by asking for the ``app.mailer `` service like this::
144162
@@ -155,6 +173,25 @@ This means that when using the container directly, you can access the
155173 # ...
156174 app.mailer : ' @App\Mail\PhpMailer'
157175
176+ .. tip ::
177+
178+ When using ``#[AsAlias] `` attribute, you may omit passing ``id `` argument
179+ if the class implements exactly one interface. ``MailerInterface `` will be
180+ alias of ``PhpMailer ``::
181+
182+ // src/Mail/PhpMailer.php
183+ namespace App\Mail;
184+
185+ // ...
186+ use Symfony\Component\DependencyInjection\Attribute\AsAlias;
187+ use Symfony\Component\Mailer\MailerInterface;
188+
189+ #[AsAlias]
190+ class PhpMailer implements MailerInterface
191+ {
192+ // ...
193+ }
194+
158195Deprecating Service Aliases
159196~~~~~~~~~~~~~~~~~~~~~~~~~~~
160197
0 commit comments