File tree Expand file tree Collapse file tree 1 file changed +27
-2
lines changed
Expand file tree Collapse file tree 1 file changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -132,8 +132,33 @@ available in the ``configure()`` method::
132132Registering the Command
133133-----------------------
134134
135- Symfony commands must be registered as services and :doc: `tagged </service_container/tags >`
136- with the ``console.command `` tag. If you're using the
135+ In PHP 8 and newer versions, you can register the command by adding the
136+ ``AsCommand `` attribute to it::
137+
138+ // src/Command/CreateUserCommand.php
139+ namespace App\Command;
140+
141+ use Symfony\Component\Console\Attribute\AsCommand;
142+ use Symfony\Component\Console\Command\Command;
143+
144+ #[AsCommand(
145+ name: 'app:create-user',
146+ description: 'Creates a new user.',
147+ hidden: false,
148+ aliases: ['app:add-user']
149+ )]
150+ class CreateUserCommand extends Command
151+ {
152+ // ...
153+ }
154+
155+ .. versionadded :: 5.3
156+
157+ The ability to use PHP attributes to configure commands was introduced in
158+ Symfony 5.3.
159+
160+ If you can't use PHP attributes, register the command as a service and
161+ :doc: `tag it </service_container/tags >` with the ``console.command `` tag. If you're using the
137162:ref: `default services.yaml configuration <service-container-services-load-example >`,
138163this is already done for you, thanks to :ref: `autoconfiguration <services-autoconfigure >`.
139164
You can’t perform that action at this time.
0 commit comments