@@ -146,13 +146,12 @@ You can optionally define a description, help message and the
146
146
// ...
147
147
class CreateUserCommand extends Command
148
148
{
149
- // the command description shown when running "php bin/console list"
150
- protected static $defaultDescription = 'Creates a new user.';
151
-
152
149
// ...
153
150
protected function configure(): void
154
151
{
155
152
$this
153
+ // the command description shown when running "php bin/console list"
154
+ ->setDescription('Creates a new user.')
156
155
// the command help shown when running the command with the "--help" option
157
156
->setHelp('This command allows you to create a user...')
158
157
;
@@ -161,15 +160,16 @@ You can optionally define a description, help message and the
161
160
162
161
.. tip ::
163
162
164
- Defining the ``$defaultDescription `` static property instead of using the
165
- ``setDescription() `` method allows to get the command description without
163
+ Using the ``#[AsCommand] `` attribute to define a description instead of
164
+ using the ``setDescription() `` method allows to get the command description without
166
165
instantiating its class. This makes the ``php bin/console list `` command run
167
166
much faster.
168
167
169
168
If you want to always run the ``list `` command fast, add the ``--short `` option
170
169
to it (``php bin/console list --short ``). This will avoid instantiating command
171
170
classes, but it won't show any description for commands that use the
172
- ``setDescription() `` method instead of the static property.
171
+ ``setDescription() `` method instead of the attribute to define the command
172
+ description.
173
173
174
174
The ``configure() `` method is called automatically at the end of the command
175
175
constructor. If your command defines its own constructor, set the properties
@@ -216,8 +216,6 @@ You can register the command by adding the ``AsCommand`` attribute to it::
216
216
use Symfony\Component\Console\Attribute\AsCommand;
217
217
use Symfony\Component\Console\Command\Command;
218
218
219
- // the "name" and "description" arguments of AsCommand replace the
220
- // static $defaultName and $defaultDescription properties
221
219
#[AsCommand(
222
220
name: 'app:create-user',
223
221
description: 'Creates a new user.',
0 commit comments