|
0
|
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 |
|
|
|
12 |
namespace Symfony\Component\Templating\Asset; |
|
|
13 |
|
|
|
14 |
/** |
|
|
15 |
* The path packages adds a version and a base path to asset URLs. |
|
|
16 |
* |
|
|
17 |
* @author Kris Wallsmith <kris@symfony.com> |
|
|
18 |
*/ |
|
|
19 |
class PathPackage extends Package |
|
|
20 |
{ |
|
|
21 |
private $basePath; |
|
|
22 |
|
|
|
23 |
/** |
|
|
24 |
* Constructor. |
|
|
25 |
* |
|
|
26 |
* @param string $basePath The base path to be prepended to relative paths |
|
|
27 |
* @param string $version The package version |
|
|
28 |
* @param string $format The format used to apply the version |
|
|
29 |
*/ |
|
|
30 |
public function __construct($basePath = null, $version = null, $format = null) |
|
|
31 |
{ |
|
|
32 |
parent::__construct($version, $format); |
|
|
33 |
|
|
|
34 |
if (!$basePath) { |
|
|
35 |
$this->basePath = '/'; |
|
|
36 |
} else { |
|
|
37 |
if ('/' != $basePath[0]) { |
|
|
38 |
$basePath = '/'.$basePath; |
|
|
39 |
} |
|
|
40 |
|
|
|
41 |
$this->basePath = rtrim($basePath, '/').'/'; |
|
|
42 |
} |
|
|
43 |
} |
|
|
44 |
|
|
|
45 |
public function getUrl($path) |
|
|
46 |
{ |
|
|
47 |
if (false !== strpos($path, '://') || 0 === strpos($path, '//')) { |
|
|
48 |
return $path; |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
$url = $this->applyVersion($path); |
|
|
52 |
|
|
|
53 |
// apply the base path |
|
|
54 |
if ($url && '/' != $url[0]) { |
|
|
55 |
$url = $this->basePath.$url; |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
return $url; |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
/** |
|
|
62 |
* Returns the base path. |
|
|
63 |
* |
|
|
64 |
* @return string The base path |
|
|
65 |
*/ |
|
|
66 |
public function getBasePath() |
|
|
67 |
{ |
|
|
68 |
return $this->basePath; |
|
|
69 |
} |
|
|
70 |
} |