| 1 | <?php |
||
| 10 | class TokenGenerator |
||
| 11 | { |
||
| 12 | protected $sign; |
||
| 13 | protected $ttl; |
||
| 14 | protected $base64url; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Create a new TokenGenerator. |
||
| 18 | * |
||
| 19 | * `$ttl` is used for calculating the expiration time of the tokens, its default value (1440sec === 24min) |
||
| 20 | * correspond to the default `session.gc_maxlifetime`. |
||
| 21 | * |
||
| 22 | * @see http://php.net/manual/en/session.configuration.php Documentation of `session.gc-maxlifetime`. |
||
| 23 | * |
||
| 24 | * @param callable $sign Callable used for generating the token signatures. |
||
| 25 | * @param int $ttl Default Time to Live in seconds. |
||
| 26 | */ |
||
| 27 | public function __construct(callable $sign, $ttl = 1440) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Generate a CSRF token. |
||
| 44 | * |
||
| 45 | * @param int $iat The time that the token was issued, defaults to `time()` |
||
| 46 | * @param int $exp The expiration time, defaults to `$iat + $this->ttl` |
||
| 47 | * |
||
| 48 | * @return string |
||
| 49 | * |
||
| 50 | * @throws \InvalidArgumentException For invalid $iat and $exp arguments. |
||
| 51 | */ |
||
| 52 | public function __invoke($iat = null, $exp = null) |
||
| 85 | } |
||
| 86 |