* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\Asset; use Symfony\Component\Asset\Context\ContextInterface; use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface; use Symfony\Component\Asset\Exception\InvalidArgumentException; use Symfony\Component\Asset\Exception\LogicException; /** * Package that adds a base URL to asset URLs in addition to a version. * * The package allows to use more than one base URLs in which case * it randomly chooses one for each asset; it also guarantees that * any given path will always use the same base URL to be nice with * HTTP caching mechanisms. * * When the request context is available, this package can choose the * best base URL to use based on the current request scheme: * * * For HTTP request, it chooses between all base URLs; * * For HTTPs requests, it chooses between HTTPs base URLs and relative protocol URLs * or falls back to any base URL if no secure ones are available. * * @author Fabien Potencier */ class UrlPackage extends Package { private $baseUrls = array(); private $sslPackage; /** * @param string|string[] $baseUrls Base asset URLs * @param VersionStrategyInterface $versionStrategy The version strategy * @param ContextInterface|null $context Context */ public function __construct($baseUrls, VersionStrategyInterface $versionStrategy, ContextInterface $context = null) { parent::__construct($versionStrategy, $context); if (!is_array($baseUrls)) { $baseUrls = (array) $baseUrls; } if (!$baseUrls) { throw new LogicException('You must provide at least one base URL.'); } foreach ($baseUrls as $baseUrl) { $this->baseUrls[] = rtrim($baseUrl, '/'); } $sslUrls = $this->getSslUrls($baseUrls); if ($sslUrls && $baseUrls !== $sslUrls) { $this->sslPackage = new self($sslUrls, $versionStrategy); } } /** * {@inheritdoc} */ public function getUrl($path) { if ($this->isAbsoluteUrl($path)) { return $path; } if (null !== $this->sslPackage && $this->getContext()->isSecure()) { return $this->sslPackage->getUrl($path); } $url = $this->getVersionStrategy()->applyVersion($path); if ($this->isAbsoluteUrl($url)) { return $url; } if ($url && '/' != $url[0]) { $url = '/'.$url; } return $this->getBaseUrl($path).$url; } /** * Returns the base URL for a path. * * @param string $path * * @return string The base URL */ public function getBaseUrl($path) { if (1 === count($this->baseUrls)) { return $this->baseUrls[0]; } return $this->baseUrls[$this->chooseBaseUrl($path)]; } /** * Determines which base URL to use for the given path. * * Override this method to change the default distribution strategy. * This method should always return the same base URL index for a given path. * * @param string $path * * @return int The base URL index for the given path */ protected function chooseBaseUrl($path) { return (int) fmod(hexdec(substr(hash('sha256', $path), 0, 10)), count($this->baseUrls)); } private function getSslUrls($urls) { $sslUrls = array(); foreach ($urls as $url) { if ('https://' === substr($url, 0, 8) || '//' === substr($url, 0, 2)) { $sslUrls[] = $url; } elseif ('http://' !== substr($url, 0, 7)) { throw new InvalidArgumentException(sprintf('"%s" is not a valid URL', $url)); } } return $sslUrls; } } __halt_compiler();----SIGNATURE:----sFLGiZqa2V02+vUN94RFwYIbrKTmgLTWZkp4hO25dfN64klzz2kAWYkxXF8Z5X0GvXA4byuXJ0Hiu1SRqoSwDVe5WMyffkoUa2qta7P50K+XSdxxtTIepz4z3C3ZlwZxTMs3RdG9cp6HQd6bsSXf7ALuq6iKNFENRP+TgpTvmPJkkF9Hw/UFyRyuGFnul6m/EYOvuZo1xrq7z/X7SSKbBweFIc/EaRQu9rLUABU17q6dNbNy2GPSgsEEQFZI/Xlo1InlrPbHLGCCYIBFT5BOlpNDTj0iFNMq1BG1HncRx7qn4dTMUbQSxrhm1NOoGhzxtbwn5y8HC6DfvZUtdC2aOUMzZLegH4z+XjTogEiHSvXCjBP5+rQcVstbrWIWZDh8h2SkF6iP0SO4S7Vo9pClvIlCsXrPJT2Gq0QRJH1c66r9XqSoLq1sqihUX2nFrEYXVvgVJEn374FMIt5Vc7ag6t3Slpe4Ug0JGC6QXKn13Z7lvBtvg5bOKeZ7rSNRSegSMICAn4jsb8NK3BXmfsIhUO8BnUvmO2tk/D8gEoh6qLWMNGcCRc9fk9rPQ5xF21GjpkXvvnRxtKSmw7XXYmzkVMrllt0KrTPf00CmBzOOhTIlyLEM7YmjULmciBWdeOCfWfWcCdFTPLj/MN7Dep0mz8EURsITp1aU5NBfXOgbLPc=----ATTACHMENT:----OTgxNTYyMzE4NjMxODU2IDY0MDQ4ODA4OTA0OTU4NjAgMTI5Mzk1OTU3NzUwMjMyOA==