@@ 13-38 (lines=26) @@ | ||
10 | /** |
|
11 | * @author Kevin Bond <[email protected]> |
|
12 | */ |
|
13 | final class ExpiresAtValidator implements Validator |
|
14 | { |
|
15 | private $currentTime; |
|
16 | ||
17 | /** |
|
18 | * @param \DateTime|null $currentTime |
|
19 | */ |
|
20 | public function __construct(\DateTime $currentTime = null) |
|
21 | { |
|
22 | $this->currentTime = $currentTime ?: new \DateTime('now'); |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function validate(Token $token) |
|
29 | { |
|
30 | if (null === $token->expiresAt()) { |
|
31 | throw new MissingClaim(Token::CLAIM_EXP, $token); |
|
32 | } |
|
33 | ||
34 | if ($token->isExpired($this->currentTime)) { |
|
35 | throw new ExpiredToken($token); |
|
36 | } |
|
37 | } |
|
38 | } |
|
39 |
@@ 13-38 (lines=26) @@ | ||
10 | /** |
|
11 | * @author Kevin Bond <[email protected]> |
|
12 | */ |
|
13 | final class NotBeforeValidator implements Validator |
|
14 | { |
|
15 | private $currentTime; |
|
16 | ||
17 | /** |
|
18 | * @param \DateTime|null $currentTime |
|
19 | */ |
|
20 | public function __construct(\DateTime $currentTime = null) |
|
21 | { |
|
22 | $this->currentTime = $currentTime ?: new \DateTime('now'); |
|
23 | } |
|
24 | ||
25 | /** |
|
26 | * {@inheritdoc} |
|
27 | */ |
|
28 | public function validate(Token $token) |
|
29 | { |
|
30 | if (null === $notBefore = $token->notBefore()) { |
|
31 | throw new MissingClaim(Token::CLAIM_NBF, $token); |
|
32 | } |
|
33 | ||
34 | if (false === $token->isAcceptable($this->currentTime)) { |
|
35 | throw new UnacceptableToken($token); |
|
36 | } |
|
37 | } |
|
38 | } |
|
39 |