Skip to content

Commit

Permalink
bug #107 Fix deprecation warnings in commands (jury89, chalasr)
Browse files Browse the repository at this point in the history
This PR was merged into the 0.4-dev branch.

Discussion
----------

Fix deprecation warnings in commands

This PR a follow up of #105 and it's addressing the following deprecation warnings that I'm getting when using Symfony 6.1 and the latest version of the oauth2 server bundle.

```
2022-10-13T07:48:25+00:00 [info] User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "League\Bundle\OAuth2ServerBundle\Command\CreateClientCommand" class instead.
2022-10-13T07:48:25+00:00 [info] User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "League\Bundle\OAuth2ServerBundle\Command\UpdateClientCommand" class instead.
2022-10-13T07:48:25+00:00 [info] User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "League\Bundle\OAuth2ServerBundle\Command\DeleteClientCommand" class instead.
2022-10-13T07:48:25+00:00 [info] User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "League\Bundle\OAuth2ServerBundle\Command\ListClientsCommand" class instead.
2022-10-13T07:48:25+00:00 [info] User Deprecated: Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "League\Bundle\OAuth2ServerBundle\Command\ClearExpiredTokensCommand" class instead.
```

Commits
-------

b9998c0 Add #[AsCommand] attribute for discovery and future-proofness
d2ca305 replace static property $defaultName in commands with command attributes of tag "console.command"
  • Loading branch information
chalasr committed Oct 16, 2022
2 parents 6dcf986 + b9998c0 commit ff14fe0
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Command/ClearExpiredTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
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
{
protected static $defaultName = 'league:oauth2-server:clear-expired-tokens';

/**
* @var AccessTokenManagerInterface
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CreateClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@
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;
use Symfony\Component\Console\Input\InputOption;
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
{
protected static $defaultName = 'league:oauth2-server:create-client';

/**
* @var ClientManagerInterface
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Command/DeleteClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
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
{
protected static $defaultName = 'league:oauth2-server:delete-client';

/**
* @var ClientManagerInterface
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ListClientsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
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'];

protected static $defaultName = 'league:oauth2-server:list-clients';

/**
* @var ClientManagerInterface
*/
Expand All @@ -37,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,
Expand Down
4 changes: 2 additions & 2 deletions src/Command/UpdateClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
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;
use Symfony\Component\Console\Input\InputOption;
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
{
protected static $defaultName = 'league:oauth2-server:update-client';

/**
* @var ClientManagerInterface
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Resources/config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit ff14fe0

Please sign in to comment.