From e45bd0e8bb183a04c34ec6f3520d14ee4bc8d7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chris=20M=C3=BCller?= <2566282+brotkrueml@users.noreply.github.com> Date: Wed, 6 Mar 2024 07:56:29 +0000 Subject: [PATCH] [TASK] Use attribute in commands (#237) The CreateWizardCommand can't be adjusted to use the attribute as it is set to `schedulable: false` (which is not possible with the Symfony attribute). Additionally, the DoSomethingCommand is defined as final. Releases: main --- CHANGELOG.md | 1 + Classes/Command/DoSomethingCommand.php | 7 ++++++- Classes/Command/MeowInformationCommand.php | 5 +++++ Configuration/Services.yaml | 12 ------------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 907c73b..17ebf48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/). - Use Configuration/user.tsconfig (#214) - Add return type to `ModuleController->initializeAction()` (#233) - Use PHP attribute for tagging event listener (#236) +- Use PHP attribute for tagging commands where applicable (#237) ### Fixed - Dynamic properties in ModuleController (#221) diff --git a/Classes/Command/DoSomethingCommand.php b/Classes/Command/DoSomethingCommand.php index 5410b0b..b88b64f 100644 --- a/Classes/Command/DoSomethingCommand.php +++ b/Classes/Command/DoSomethingCommand.php @@ -17,11 +17,16 @@ namespace T3docs\Examples\Command; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; -class DoSomethingCommand extends Command +#[AsCommand( + name: 'examples:dosomething', + description: 'A command that does nothing and always succeeds.', +)] +final class DoSomethingCommand extends Command { protected function configure(): void { diff --git a/Classes/Command/MeowInformationCommand.php b/Classes/Command/MeowInformationCommand.php index cba0d71..c35e0e1 100644 --- a/Classes/Command/MeowInformationCommand.php +++ b/Classes/Command/MeowInformationCommand.php @@ -18,12 +18,17 @@ namespace T3docs\Examples\Command; use Psr\Log\LoggerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use T3docs\Examples\Http\MeowInformationRequester; +#[AsCommand( + name: 'examples:meow', + description: 'Meow Information', +)] final class MeowInformationCommand extends Command { public function __construct( diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 2bd4373..f3fc265 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -12,12 +12,6 @@ services: tags: - name: linkvalidator.linktype - T3docs\Examples\Command\DoSomethingCommand: - tags: - - name: console.command - command: 'examples:dosomething' - description: 'A command that does nothing and always succeeds.' - T3docs\Examples\Command\CreateWizardCommand: tags: - name: console.command @@ -26,12 +20,6 @@ services: hidden: true schedulable: false - T3docs\Examples\Command\MeowInformationCommand: - tags: - - name: 'console.command' - command: 'examples:meow' - description: 'Meow Information' - T3docs\Examples\Controller\Haiku\DetailController: public: true