vendor/liip/imagine-bundle/Imagine/Cache/Signer.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3. * This file is part of the `liip/LiipImagineBundle` project.
  4. *
  5. * (c) https://github.com/liip/LiipImagineBundle/graphs/contributors
  6. *
  7. * For the full copyright and license information, please view the LICENSE.md
  8. * file that was distributed with this source code.
  9. */
  10. namespace Liip\ImagineBundle\Imagine\Cache;
  11. class Signer implements SignerInterface
  12. {
  13. /**
  14. * @var string
  15. */
  16. private $secret;
  17. /**
  18. * @param string $secret
  19. */
  20. public function __construct($secret)
  21. {
  22. $this->secret = $secret;
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. public function sign($path, array $runtimeConfig = null)
  28. {
  29. if ($runtimeConfig) {
  30. array_walk_recursive($runtimeConfig, function (&$value) {
  31. $value = (string) $value;
  32. });
  33. }
  34. return mb_substr(preg_replace('/[^a-zA-Z0-9-_]/', '', base64_encode(hash_hmac('sha256', ltrim($path, '/').(null === $runtimeConfig ?: serialize($runtimeConfig)), $this->secret, true))), 0, 8);
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function check($hash, $path, array $runtimeConfig = null)
  40. {
  41. return $hash === $this->sign($path, $runtimeConfig);
  42. }
  43. }