Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
CRAP
100.00% covered (success)
100.00%
10 / 10
Package
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
6 / 6
9
100.00% covered (success)
100.00%
10 / 10
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getVersion
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getUrl
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 getContext
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getVersionStrategy
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 isAbsoluteUrl
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Asset;
13
14use Symfony\Component\Asset\Context\ContextInterface;
15use Symfony\Component\Asset\Context\NullContext;
16use Symfony\Component\Asset\VersionStrategy\VersionStrategyInterface;
17
18/**
19 * Basic package that adds a version to asset URLs.
20 *
21 * @author Kris Wallsmith <kris@symfony.com>
22 * @author Fabien Potencier <fabien@symfony.com>
23 */
24class Package implements PackageInterface
25{
26    private $versionStrategy;
27    private $context;
28
29    public function __construct(VersionStrategyInterface $versionStrategy, ContextInterface $context = null)
30    {
31        $this->versionStrategy = $versionStrategy;
32        $this->context = $context ?: new NullContext();
33    }
34
35    /**
36     * {@inheritdoc}
37     */
38    public function getVersion(string $path)
39    {
40        return $this->versionStrategy->getVersion($path);
41    }
42
43    /**
44     * {@inheritdoc}
45     */
46    public function getUrl(string $path)
47    {
48        if ($this->isAbsoluteUrl($path)) {
49            return $path;
50        }
51
52        return $this->versionStrategy->applyVersion($path);
53    }
54
55    /**
56     * @return ContextInterface
57     */
58    protected function getContext()
59    {
60        return $this->context;
61    }
62
63    /**
64     * @return VersionStrategyInterface
65     */
66    protected function getVersionStrategy()
67    {
68        return $this->versionStrategy;
69    }
70
71    /**
72     * @return bool
73     */
74    protected function isAbsoluteUrl(string $url)
75    {
76        return false !== strpos($url, '://') || '//' === substr($url, 0, 2);
77    }
78}