|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Symfony framework. |
|
|
5 |
* |
|
|
6 |
* (c) Fabien Potencier <fabien@symfony.com> |
|
|
7 |
* |
|
|
8 |
* This source file is subject to the MIT license that is bundled |
|
|
9 |
* with this source code in the file LICENSE. |
|
|
10 |
*/ |
|
|
11 |
|
|
|
12 |
namespace Symfony\Bundle\AsseticBundle\Factory; |
|
|
13 |
|
|
|
14 |
use Assetic\Factory\AssetFactory as BaseAssetFactory; |
|
|
15 |
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
|
16 |
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; |
|
|
17 |
use Symfony\Component\HttpKernel\KernelInterface; |
|
|
18 |
|
|
|
19 |
/** |
|
|
20 |
* Loads asset formulae from the filesystem. |
|
|
21 |
* |
|
|
22 |
* @author Kris Wallsmith <kris@symfony.com> |
|
|
23 |
*/ |
|
|
24 |
class AssetFactory extends BaseAssetFactory |
|
|
25 |
{ |
|
|
26 |
private $kernel; |
|
|
27 |
private $container; |
|
|
28 |
private $parameterBag; |
|
|
29 |
|
|
|
30 |
/** |
|
|
31 |
* Constructor. |
|
|
32 |
* |
|
|
33 |
* @param KernelInterface $kernel The kernel is used to parse bundle notation |
|
|
34 |
* @param ContainerInterface $container The container is used to load the managers lazily, thus avoiding a circular dependency |
|
|
35 |
* @param ParameterBagInterface $parameterBag The container parameter bag |
|
|
36 |
* @param string $baseDir The base directory for relative inputs |
|
|
37 |
* @param Boolean $debug The current debug mode |
|
|
38 |
*/ |
|
|
39 |
public function __construct(KernelInterface $kernel, ContainerInterface $container, ParameterBagInterface $parameterBag, $baseDir, $debug = false) |
|
|
40 |
{ |
|
|
41 |
$this->kernel = $kernel; |
|
|
42 |
$this->container = $container; |
|
|
43 |
$this->parameterBag = $parameterBag; |
|
|
44 |
|
|
|
45 |
parent::__construct($baseDir, $debug); |
|
|
46 |
} |
|
|
47 |
|
|
|
48 |
/** |
|
|
49 |
* Adds support for bundle notation file and glob assets and parameter placeholders. |
|
|
50 |
* |
|
|
51 |
* FIXME: This is a naive implementation of globs in that it doesn't |
|
|
52 |
* attempt to support bundle inheritance within the glob pattern itself. |
|
|
53 |
*/ |
|
|
54 |
protected function parseInput($input, array $options = array()) |
|
|
55 |
{ |
|
|
56 |
$input = $this->parameterBag->resolveValue($input); |
|
|
57 |
|
|
|
58 |
// expand bundle notation |
|
|
59 |
if ('@' == $input[0] && false !== strpos($input, '/')) { |
|
|
60 |
// use the bundle path as this asset's root |
|
|
61 |
$bundle = substr($input, 1); |
|
|
62 |
if (false !== $pos = strpos($bundle, '/')) { |
|
|
63 |
$bundle = substr($bundle, 0, $pos); |
|
|
64 |
} |
|
|
65 |
$options['root'] = array($this->kernel->getBundle($bundle)->getPath()); |
|
|
66 |
|
|
|
67 |
// canonicalize the input |
|
|
68 |
if (false !== $pos = strpos($input, '*')) { |
|
|
69 |
// locateResource() does not support globs so we provide a naive implementation here |
|
|
70 |
list($before, $after) = explode('*', $input, 2); |
|
|
71 |
$input = $this->kernel->locateResource($before).'*'.$after; |
|
|
72 |
} else { |
|
|
73 |
$input = $this->kernel->locateResource($input); |
|
|
74 |
} |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
return parent::parseInput($input, $options); |
|
|
78 |
} |
|
|
79 |
|
|
|
80 |
protected function createAssetReference($name) |
|
|
81 |
{ |
|
|
82 |
if (!$this->getAssetManager()) { |
|
|
83 |
$this->setAssetManager($this->container->get('assetic.asset_manager')); |
|
|
84 |
} |
|
|
85 |
|
|
|
86 |
return parent::createAssetReference($name); |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
protected function getFilter($name) |
|
|
90 |
{ |
|
|
91 |
if (!$this->getFilterManager()) { |
|
|
92 |
$this->setFilterManager($this->container->get('assetic.filter_manager')); |
|
|
93 |
} |
|
|
94 |
|
|
|
95 |
return parent::getFilter($name); |
|
|
96 |
} |
|
|
97 |
} |