| Total Complexity | 5 |
| Total Lines | 21 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 6 | class NonceGenerator { |
||
| 7 | |||
| 8 | private array $nonces = []; |
||
| 9 | |||
| 10 | private ?callable $onNonce; |
||
| 11 | |||
| 12 | public function __construct(?callable $onNonce) { |
||
| 13 | $this->onNonce = $onNonce; |
||
| 14 | } |
||
| 15 | |||
| 16 | protected function _generateNonce(string $name, ?int $value = null): string { |
||
| 17 | $bytes = \random_bytes((int) ($value ?? 32)); |
||
| 18 | $nonce = \base64_encode($bytes); |
||
| 19 | if (isset($this->onNonce) && ! URequest::isAjax()) { |
||
| 20 | $this->{onNonce}($name, $nonce); |
||
|
|
|||
| 21 | } |
||
| 22 | return $nonce; |
||
| 23 | } |
||
| 24 | |||
| 25 | public function getNonce(string $name) { |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 |