Skip to content

Commit de9d549

Browse files
committed
[Console] Document AsCommand attribute
1 parent 8f64f04 commit de9d549

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

console.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,29 @@ with the ``console.command`` tag. If you're using the
151151
:ref:`default services.yaml configuration <service-container-services-load-example>`,
152152
this is already done for you, thanks to :ref:`autoconfiguration <services-autoconfigure>`.
153153

154+
On PHP 8, you can use native attribute ``AsCommand`` to configure::
155+
156+
// src/Command/CreateUserCommand.php
157+
namespace App\Command;
158+
159+
use Symfony\Component\Console\Attribute\AsCommand;
160+
use Symfony\Component\Console\Command\Command;
161+
162+
#[AsCommand(
163+
name: 'app:create-user',
164+
description: 'Creates a new user.',
165+
aliases: [app:add-user']
166+
)]
167+
class CreateUserCommand extends Command
168+
{
169+
// ...
170+
}
171+
172+
.. versionadded:: 5.3
173+
174+
The ability to use PHP attributes to configure commands was introduced in
175+
Symfony 5.3.
176+
154177
Executing the Command
155178
---------------------
156179

0 commit comments

Comments
 (0)