| 1 | <?php |
||
| 5 | class Signer implements SignerInterface |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var string |
||
| 9 | */ |
||
| 10 | private $secret; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @param string $secret |
||
| 14 | */ |
||
| 15 | public function __construct($secret) |
||
| 19 | |||
| 20 | /** |
||
| 21 | * {@inheritdoc} |
||
| 22 | */ |
||
| 23 | public function sign($path, array $runtimeConfig = null) |
||
| 24 | { |
||
| 25 | if ($runtimeConfig) { |
||
| 26 | array_walk_recursive($runtimeConfig, function (&$value) { |
||
| 27 | $value = (string) $value; |
||
| 28 | }); |
||
| 29 | } |
||
| 30 | |||
| 31 | return substr(preg_replace('/[^a-zA-Z0-9-_]/', '', base64_encode(hash_hmac('sha256', ltrim($path, '/').(null === $runtimeConfig ?: serialize($runtimeConfig)), $this->secret, true))), 0, 8); |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * {@inheritdoc} |
||
| 36 | */ |
||
| 37 | public function check($hash, $path, array $runtimeConfig = null) |
||
| 41 | } |
||
| 42 |