-
Notifications
You must be signed in to change notification settings - Fork 548
Expand file tree
/
Copy pathAsseticExtension.php
More file actions
75 lines (62 loc) · 2.02 KB
/
AsseticExtension.php
File metadata and controls
75 lines (62 loc) · 2.02 KB
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
<?php
/*
* This file is part of the Assetic package, an OpenSky project.
*
* (c) 2010-2014 OpenSky Project Inc
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Assetic\Extension\Twig;
use Assetic\Factory\AssetFactory;
use Assetic\ValueSupplierInterface;
class AsseticExtension extends \Twig_Extension implements \Twig_Extension_GlobalsInterface
{
protected $factory;
protected $functions;
protected $valueSupplier;
public function __construct(AssetFactory $factory, $functions = [], ValueSupplierInterface $valueSupplier = null)
{
$this->factory = $factory;
$this->functions = [];
$this->valueSupplier = $valueSupplier;
foreach ($functions as $function => $options) {
$this->functions[$options] = is_integer($function) && is_string($options)
? ['filter' => $options]
: $options + ['filter' => $function];
}
}
public function getTokenParsers()
{
return [
new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js'),
new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css'),
new AsseticTokenParser($this->factory, 'image', 'images/*', true),
];
}
public function getFunctions()
{
$functions = [];
foreach ($this->functions as $function => $filter) {
$functions[] = new AsseticFilterFunction($function);
}
return $functions;
}
public function getGlobals()
{
return [
'assetic' => [
'debug' => $this->factory->isDebug(),
'vars' => null !== $this->valueSupplier ? new ValueContainer($this->valueSupplier) : [],
],
];
}
public function getFilterInvoker($function)
{
return new AsseticFilterInvoker($this->factory, $this->functions[$function]);
}
public function getName()
{
return 'assetic';
}
}