diff --git a/console.rst b/console.rst index 042554fe006..9215f07d7c6 100644 --- a/console.rst +++ b/console.rst @@ -151,6 +151,30 @@ with the ``console.command`` tag. If you're using the :ref:`default services.yaml configuration `, this is already done for you, thanks to :ref:`autoconfiguration `. +On PHP 8, you can use native attribute ``AsCommand`` to configure:: + + // src/Command/CreateUserCommand.php + namespace App\Command; + + use Symfony\Component\Console\Attribute\AsCommand; + use Symfony\Component\Console\Command\Command; + + #[AsCommand( + name: 'app:create-user', + description: 'Creates a new user.', + hidden: false, + aliases: ['app:add-user'] + )] + class CreateUserCommand extends Command + { + // ... + } + +.. versionadded:: 5.3 + + The ability to use PHP attributes to configure commands was introduced in + Symfony 5.3. + Executing the Command ---------------------