AssetPackage.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Templating\Asset;
  11. /**
  12. * An asset package.
  13. *
  14. * @author Kris Wallsmith <kris@symfony.com>
  15. */
  16. class AssetPackage implements AssetPackageInterface
  17. {
  18. private $baseUrls;
  19. private $version;
  20. /**
  21. * Constructor.
  22. *
  23. * @param array|string $baseUrls The domain URL or an array of domain URLs
  24. * @param string $version The version
  25. */
  26. public function __construct($baseUrls = array(), $version = null)
  27. {
  28. $this->baseUrls = array();
  29. $this->version = $version;
  30. foreach ((array) $baseUrls as $baseUrl) {
  31. $this->baseUrls[] = rtrim($baseUrl, '/');
  32. }
  33. }
  34. public function getVersion()
  35. {
  36. return $this->version;
  37. }
  38. public function getBaseUrl($path)
  39. {
  40. $count = count($this->baseUrls);
  41. if (0 === $count) {
  42. return '';
  43. }
  44. if (1 === $count) {
  45. return $this->baseUrls[0];
  46. }
  47. return $this->baseUrls[fmod(hexdec(substr(md5($path), 0, 10)), $count)];
  48. }
  49. }