Total Complexity | 9 |
Total Lines | 53 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class AuthorizationMiddleware implements Middleware |
||
11 | { |
||
12 | /** |
||
13 | * @var string |
||
14 | */ |
||
15 | private $expirationPeriod; |
||
16 | |||
17 | public function __construct($expirationPeriod = '1 day') |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @param BaseCommand $command |
||
24 | * |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function execute($command, callable $next) |
||
28 | { |
||
29 | if (!$command->storage) { |
||
30 | throw new \LogicException("Require storage before using this middleware!"); |
||
31 | } |
||
32 | |||
33 | if (!$command->secured && LoginCommand::CMD !== $command->storage->getLineActiveCmd()) { |
||
34 | return $next($command); |
||
35 | } |
||
36 | |||
37 | if (!$this->isSecureExpired($command->storage)) { |
||
38 | return $next($command); |
||
39 | } |
||
40 | |||
41 | $command->switchTo(LoginCommand::class); |
||
42 | |||
43 | return $next($command); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param User $user |
||
48 | * |
||
49 | * @return bool |
||
50 | */ |
||
51 | private function isSecureExpired(User $user) |
||
63 | } |
||
64 | } |
||
65 |