-
Notifications
You must be signed in to change notification settings - Fork 450
/
Copy pathCleanCommand.php
82 lines (68 loc) · 2.18 KB
/
CleanCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
declare(strict_types=1);
/*
* This file is part of the FOSOAuthServerBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\OAuthServerBundle\Command;
use FOS\OAuthServerBundle\Model\AuthCodeManagerInterface;
use FOS\OAuthServerBundle\Model\TokenManagerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class CleanCommand extends Command
{
/** @var TokenManagerInterface */
private $accessTokenManager;
/** @var TokenManagerInterface */
private $refreshTokenManager;
/** @var AuthCodeManagerInterface */
private $authCodeManager;
public function __construct(
TokenManagerInterface $accessTokenManager,
TokenManagerInterface $refreshTokenManager,
AuthCodeManagerInterface $authCodeManager
) {
parent::__construct();
$this->accessTokenManager = $accessTokenManager;
$this->refreshTokenManager = $refreshTokenManager;
$this->authCodeManager = $authCodeManager;
}
/**
* {@inheritdoc}
*/
protected function configure(): void
{
parent::configure();
$this
->setName('fos:oauth-server:clean')
->setDescription('Clean expired tokens')
->setHelp(<<<EOT
The <info>%command.name%</info> command will remove expired OAuth2 tokens.
<info>php %command.full_name%</info>
EOT
)
;
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
foreach ([$this->accessTokenManager, $this->refreshTokenManager, $this->authCodeManager] as $service) {
$result = $service->deleteExpired();
$output->writeln(
sprintf(
'Removed <info>%d</info> items from <comment>%s</comment> storage.',
$result,
get_class($service)
)
);
}
return 0;
}
}