File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -132,8 +132,28 @@ available in the ``configure()`` method::
132
132
Registering the Command
133
133
-----------------------
134
134
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
+ If you can't use PHP attributes, register the command as a service and
156
+ :doc: `tag it </service_container/tags >` with the ``console.command `` tag. If you're using the
137
157
:ref: `default services.yaml configuration <service-container-services-load-example >`,
138
158
this is already done for you, thanks to :ref: `autoconfiguration <services-autoconfigure >`.
139
159
You can’t perform that action at this time.
0 commit comments