Skip to content

Commit 189d0c9

Browse files
committed
minor #18473 [Console] Remove occurrences of $defaultName and $defaultDescription (alexandre-daubois)
This PR was merged into the 7.0 branch. Discussion ---------- [Console] Remove occurrences of `$defaultName` and `$defaultDescription` Fix #18472 Commits ------- 2d674cf [Console] Remove occurrences of `$defaultName` and `$defaultDescription`
2 parents e51f8fd + 2d674cf commit 189d0c9

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
.. deprecated:: 6.1
175175

@@ -222,8 +222,6 @@ You can register the command by adding the ``AsCommand`` attribute to it::
222222
use Symfony\Component\Console\Attribute\AsCommand;
223223
use Symfony\Component\Console\Command\Command;
224224

225-
// the "name" and "description" arguments of AsCommand replace the
226-
// static $defaultName and $defaultDescription properties
227225
#[AsCommand(
228226
name: 'app:create-user',
229227
description: 'Creates a new user.',

0 commit comments

Comments
 (0)