vendor/symfony/asset/Package.php line 29

Open in your IDE?
  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;
  11. use Symfony\Component\Asset\Context\ContextInterface;
  12. use Symfony\Component\Asset\Context\NullContext;
  13. use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
  14. /**
  15.  * Basic package that adds a version to asset URLs.
  16.  *
  17.  * @author Kris Wallsmith <kris@symfony.com>
  18.  * @author Fabien Potencier <fabien@symfony.com>
  19.  */
  20. class Package implements PackageInterface
  21. {
  22.     private $versionStrategy;
  23.     private $context;
  24.     public function __construct(VersionStrategyInterface $versionStrategyContextInterface $context null)
  25.     {
  26.         $this->versionStrategy $versionStrategy;
  27.         $this->context $context ?? new NullContext();
  28.     }
  29.     /**
  30.      * {@inheritdoc}
  31.      */
  32.     public function getVersion(string $path)
  33.     {
  34.         return $this->versionStrategy->getVersion($path);
  35.     }
  36.     /**
  37.      * {@inheritdoc}
  38.      */
  39.     public function getUrl(string $path)
  40.     {
  41.         if ($this->isAbsoluteUrl($path)) {
  42.             return $path;
  43.         }
  44.         return $this->versionStrategy->applyVersion($path);
  45.     }
  46.     /**
  47.      * @return ContextInterface
  48.      */
  49.     protected function getContext()
  50.     {
  51.         return $this->context;
  52.     }
  53.     /**
  54.      * @return VersionStrategyInterface
  55.      */
  56.     protected function getVersionStrategy()
  57.     {
  58.         return $this->versionStrategy;
  59.     }
  60.     /**
  61.      * @return bool
  62.      */
  63.     protected function isAbsoluteUrl(string $url)
  64.     {
  65.         return str_contains($url'://') || '//' === substr($url02);
  66.     }
  67. }