From d2ca305c34924bc3293a213ec4a0245fd4a05101 Mon Sep 17 00:00:00 2001 From: Jury D'Ambros Date: Thu, 13 Oct 2022 12:07:04 +0200 Subject: [PATCH 1/2] replace static property $defaultName in commands with command attributes of tag "console.command" --- src/Command/ClearExpiredTokensCommand.php | 2 -- src/Command/CreateClientCommand.php | 2 -- src/Command/DeleteClientCommand.php | 2 -- src/Command/ListClientsCommand.php | 2 -- src/Command/UpdateClientCommand.php | 2 -- src/Resources/config/services.php | 10 +++++----- 6 files changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Command/ClearExpiredTokensCommand.php b/src/Command/ClearExpiredTokensCommand.php index 706ea2b4..2d37c528 100644 --- a/src/Command/ClearExpiredTokensCommand.php +++ b/src/Command/ClearExpiredTokensCommand.php @@ -15,8 +15,6 @@ final class ClearExpiredTokensCommand extends Command { - protected static $defaultName = 'league:oauth2-server:clear-expired-tokens'; - /** * @var AccessTokenManagerInterface */ diff --git a/src/Command/CreateClientCommand.php b/src/Command/CreateClientCommand.php index ab5b00db..dec3e098 100644 --- a/src/Command/CreateClientCommand.php +++ b/src/Command/CreateClientCommand.php @@ -18,8 +18,6 @@ final class CreateClientCommand extends Command { - protected static $defaultName = 'league:oauth2-server:create-client'; - /** * @var ClientManagerInterface */ diff --git a/src/Command/DeleteClientCommand.php b/src/Command/DeleteClientCommand.php index 874630b1..725feb8f 100644 --- a/src/Command/DeleteClientCommand.php +++ b/src/Command/DeleteClientCommand.php @@ -13,8 +13,6 @@ final class DeleteClientCommand extends Command { - protected static $defaultName = 'league:oauth2-server:delete-client'; - /** * @var ClientManagerInterface */ diff --git a/src/Command/ListClientsCommand.php b/src/Command/ListClientsCommand.php index 371b76d4..5e297794 100644 --- a/src/Command/ListClientsCommand.php +++ b/src/Command/ListClientsCommand.php @@ -20,8 +20,6 @@ final class ListClientsCommand extends Command { private const ALLOWED_COLUMNS = ['name', 'identifier', 'secret', 'scope', 'redirect uri', 'grant type']; - protected static $defaultName = 'league:oauth2-server:list-clients'; - /** * @var ClientManagerInterface */ diff --git a/src/Command/UpdateClientCommand.php b/src/Command/UpdateClientCommand.php index 0926aecc..ba4cd96f 100644 --- a/src/Command/UpdateClientCommand.php +++ b/src/Command/UpdateClientCommand.php @@ -17,8 +17,6 @@ final class UpdateClientCommand extends Command { - protected static $defaultName = 'league:oauth2-server:update-client'; - /** * @var ClientManagerInterface */ diff --git a/src/Resources/config/services.php b/src/Resources/config/services.php index 4829b01c..f9c4a600 100644 --- a/src/Resources/config/services.php +++ b/src/Resources/config/services.php @@ -235,28 +235,28 @@ service(ClientManagerInterface::class), null, ]) - ->tag('console.command') + ->tag('console.command', ['command' => 'league:oauth2-server:create-client']) ->alias(CreateClientCommand::class, 'league.oauth2_server.command.create_client') ->set('league.oauth2_server.command.update_client', UpdateClientCommand::class) ->args([ service(ClientManagerInterface::class), ]) - ->tag('console.command') + ->tag('console.command', ['command' => 'league:oauth2-server:update-client']) ->alias(UpdateClientCommand::class, 'league.oauth2_server.command.update_client') ->set('league.oauth2_server.command.delete_client', DeleteClientCommand::class) ->args([ service(ClientManagerInterface::class), ]) - ->tag('console.command') + ->tag('console.command', ['command' => 'league:oauth2-server:delete-client']) ->alias(DeleteClientCommand::class, 'league.oauth2_server.command.delete_client') ->set('league.oauth2_server.command.list_clients', ListClientsCommand::class) ->args([ service(ClientManagerInterface::class), ]) - ->tag('console.command') + ->tag('console.command', ['command' => 'league:oauth2-server:list-clients']) ->alias(ListClientsCommand::class, 'league.oauth2_server.command.list_clients') ->set('league.oauth2_server.command.clear_expired_tokens', ClearExpiredTokensCommand::class) @@ -265,7 +265,7 @@ service(RefreshTokenManagerInterface::class), service(AuthorizationCodeManagerInterface::class), ]) - ->tag('console.command') + ->tag('console.command', ['command' => 'league:oauth2-server:clear-expired-tokens']) ->alias(ClearExpiredTokensCommand::class, 'league.oauth2_server.command.clear_expired_tokens') // Utility services From b9998c0311328aeace4c79bd5f184ef3553857e8 Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sun, 16 Oct 2022 18:20:21 +0200 Subject: [PATCH 2/2] Add #[AsCommand] attribute for discovery and future-proofness --- src/Command/ClearExpiredTokensCommand.php | 2 ++ src/Command/CreateClientCommand.php | 2 ++ src/Command/DeleteClientCommand.php | 2 ++ src/Command/ListClientsCommand.php | 4 +++- src/Command/UpdateClientCommand.php | 2 ++ 5 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Command/ClearExpiredTokensCommand.php b/src/Command/ClearExpiredTokensCommand.php index 2d37c528..16c6985b 100644 --- a/src/Command/ClearExpiredTokensCommand.php +++ b/src/Command/ClearExpiredTokensCommand.php @@ -7,12 +7,14 @@ use League\Bundle\OAuth2ServerBundle\Manager\AccessTokenManagerInterface; use League\Bundle\OAuth2ServerBundle\Manager\AuthorizationCodeManagerInterface; use League\Bundle\OAuth2ServerBundle\Manager\RefreshTokenManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'league:oauth2-server:clear-expired-tokens', description: 'Clears all expired access and/or refresh tokens and/or auth codes')] final class ClearExpiredTokensCommand extends Command { /** diff --git a/src/Command/CreateClientCommand.php b/src/Command/CreateClientCommand.php index dec3e098..a6b66ea3 100644 --- a/src/Command/CreateClientCommand.php +++ b/src/Command/CreateClientCommand.php @@ -9,6 +9,7 @@ use League\Bundle\OAuth2ServerBundle\ValueObject\Grant; use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri; use League\Bundle\OAuth2ServerBundle\ValueObject\Scope; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -16,6 +17,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'league:oauth2-server:create-client', description: 'Creates a new OAuth2 client')] final class CreateClientCommand extends Command { /** diff --git a/src/Command/DeleteClientCommand.php b/src/Command/DeleteClientCommand.php index 725feb8f..73302780 100644 --- a/src/Command/DeleteClientCommand.php +++ b/src/Command/DeleteClientCommand.php @@ -5,12 +5,14 @@ namespace League\Bundle\OAuth2ServerBundle\Command; use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'league:oauth2-server:delete-client', description: 'Deletes an OAuth2 client')] final class DeleteClientCommand extends Command { /** diff --git a/src/Command/ListClientsCommand.php b/src/Command/ListClientsCommand.php index 5e297794..6e720473 100644 --- a/src/Command/ListClientsCommand.php +++ b/src/Command/ListClientsCommand.php @@ -10,12 +10,14 @@ use League\Bundle\OAuth2ServerBundle\ValueObject\Grant; use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri; use League\Bundle\OAuth2ServerBundle\ValueObject\Scope; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'league:oauth2-server:list-clients', description: 'Lists existing OAuth2 clients')] final class ListClientsCommand extends Command { private const ALLOWED_COLUMNS = ['name', 'identifier', 'secret', 'scope', 'redirect uri', 'grant type']; @@ -35,7 +37,7 @@ public function __construct(ClientManagerInterface $clientManager) protected function configure(): void { $this - ->setDescription('Lists existing oAuth2 clients') + ->setDescription('Lists existing OAuth2 clients') ->addOption( 'columns', null, diff --git a/src/Command/UpdateClientCommand.php b/src/Command/UpdateClientCommand.php index ba4cd96f..c462a60d 100644 --- a/src/Command/UpdateClientCommand.php +++ b/src/Command/UpdateClientCommand.php @@ -8,6 +8,7 @@ use League\Bundle\OAuth2ServerBundle\ValueObject\Grant; use League\Bundle\OAuth2ServerBundle\ValueObject\RedirectUri; use League\Bundle\OAuth2ServerBundle\ValueObject\Scope; +use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -15,6 +16,7 @@ use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +#[AsCommand(name: 'league:oauth2-server:update-client', description: 'Updates an OAuth2 client')] final class UpdateClientCommand extends Command { /**