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