Skip to content

Commit a1a5933

Browse files
committed
minor #16333 [Console] Document AsCommand attribute (94noni)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Console] Document AsCommand attribute Replaces #15123 as it seems stale Close #15003 Friendly ping `@OskarStark` for original PR review Commits ------- 7a842f1 [Console] Document AsCommand attribute
2 parents f4bc859 + 7a842f1 commit a1a5933

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

console.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,30 @@ 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+
hidden: false,
166+
aliases: ['app:add-user']
167+
)]
168+
class CreateUserCommand extends Command
169+
{
170+
// ...
171+
}
172+
173+
.. versionadded:: 5.3
174+
175+
The ability to use PHP attributes to configure commands was introduced in
176+
Symfony 5.3.
177+
154178
Executing the Command
155179
---------------------
156180

0 commit comments

Comments
 (0)