StaticVersionStrategy.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Asset\VersionStrategy;
  11. /**
  12. * Returns the same version for all assets.
  13. *
  14. * @author Fabien Potencier <fabien@symfony.com>
  15. */
  16. class StaticVersionStrategy implements VersionStrategyInterface
  17. {
  18. private $version;
  19. private $format;
  20. /**
  21. * @param string $version Version number
  22. * @param string $format Url format
  23. */
  24. public function __construct(string $version, string $format = null)
  25. {
  26. $this->version = $version;
  27. $this->format = $format ?: '%s?%s';
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function getVersion(string $path)
  33. {
  34. return $this->version;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function applyVersion(string $path)
  40. {
  41. $versionized = sprintf($this->format, ltrim($path, '/'), $this->getVersion($path));
  42. if ($path && '/' == $path[0]) {
  43. return '/'.$versionized;
  44. }
  45. return $versionized;
  46. }
  47. }