10000 [Console] Remove occurrences of `$defaultName` and `$defaultDescription` · symfony/symfony-docs@2d674cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 2d674cf

Browse files
[Console] Remove occurrences of $defaultName and $defaultDescription
1 parent c598bde commit 2d674cf

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

console.rst

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,12 @@ You can optionally define a description, help message and the
146146
// ...
147147
class CreateUserCommand extends Command
148148
{
149-
// the command description shown when running "php bin/console list"
150-
protected static $defaultDescription = 'Creates a new user.';
151-
152149
// ...
153150
protected function configure(): void
154151
{
155152
$this
153+
// the command description shown when running "php bin/console list"
154+
->setDescription('Creates a new user.')
156155
// the command help shown when running the command with the "--help" option
157156
->setHelp('This command allows you to create a user...')
158157
;
@@ -161,15 +160,16 @@ You can optionally define a description, help message and the
161160

162161
.. tip::
163162

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
166165
instantiating its class. This makes the ``php bin/console list`` command run
167166
much faster.
168167

169168
If you want to always run the ``list`` command fast, add the ``--short`` option
170169
to it (``php bin/console list --short``). This will avoid instantiating command
171170
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.
173173

174174
The ``configure()`` method is called automatically at the end of the command
175175
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::
216216
use Symfony\Component\Console\Attribute\AsCommand;
217217
use Symfony\Component\Console\Command\Command;
218218

219-
// the "name" and "description" arguments of AsCommand replace the
220-
// static $defaultName and $defaultDescription properties
221219
#[AsCommand(
222220
name: 'app:create-user',
223221
description: 'Creates a new user.',

0 commit comments

Comments
 (0)
0