Skip to content

Commit 45f9eeb

Browse files
committed
add documentation for console command attributes
1 parent 9c6529b commit 45f9eeb

File tree

1 file changed

+31
-12
lines changed

1 file changed

+31
-12
lines changed

console.rst

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,37 @@ Configuring the Command
7979
You can optionally define a description, help message and the
8080
:doc:`input options and arguments </console/input>`::
8181

82-
// ...
83-
protected function configure()
84-
{
85-
$this
86-
// the short description shown while running "php bin/console list"
87-
->setDescription('Creates a new user.')
82+
.. versionadded:: 5.3
8883

89-
// the full command description shown when running the command with
90-
// the "--help" option
91-
->setHelp('This command allows you to create a user...')
92-
;
93-
}
84+
The ability to use PHP attributes to configure commands was introduced in
85+
Symfony 5.3.
86+
87+
.. configuration-block::
88+
89+
.. code-block:: php
90+
91+
// ...
92+
protected function configure()
93+
{
94+
$this
95+
// the short description shown while running "php bin/console list"
96+
->setDescription('Creates a new user.')
97+
98+
// the full command description shown when running the command with
99+
// the "--help" option
100+
->setHelp('This command allows you to create a user...')
101+
;
102+
}
103+
104+
.. code-block:: php-attributes
105+
106+
// ...
107+
#[ConsoleCommand(
108+
name: 'app:create-user',
109+
description: 'Creates a new user.'
110+
hidden: false,
111+
aliases: [],
112+
)]
94113
95114
The ``configure()`` method is called automatically at the end of the command
96115
constructor. If your command defines its own constructor, set the properties
@@ -418,7 +437,7 @@ call ``setAutoExit(false)`` on it to get the command result in ``CommandTester``
418437

419438
$application = new Application();
420439
$application->setAutoExit(false);
421-
440+
422441
$tester = new ApplicationTester($application);
423442

424443
.. note::

0 commit comments

Comments
 (0)