|
0
|
1 |
<?php |
|
|
2 |
|
|
|
3 |
/* |
|
|
4 |
* This file is part of the Assetic package, an OpenSky project. |
|
|
5 |
* |
|
|
6 |
* (c) 2010-2011 OpenSky Project Inc |
|
|
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 Assetic\Extension\Twig; |
|
|
13 |
|
|
|
14 |
use Assetic\Factory\AssetFactory; |
|
|
15 |
|
|
|
16 |
class AsseticExtension extends \Twig_Extension |
|
|
17 |
{ |
|
|
18 |
protected $factory; |
|
|
19 |
protected $functions; |
|
|
20 |
|
|
|
21 |
public function __construct(AssetFactory $factory, $functions = array()) |
|
|
22 |
{ |
|
|
23 |
$this->factory = $factory; |
|
|
24 |
$this->functions = array(); |
|
|
25 |
|
|
|
26 |
foreach ($functions as $function => $options) { |
|
|
27 |
if (is_integer($function) && is_string($options)) { |
|
|
28 |
$this->functions[$options] = array('filter' => $options); |
|
|
29 |
} else { |
|
|
30 |
$this->functions[$function] = $options + array('filter' => $function); |
|
|
31 |
} |
|
|
32 |
} |
|
|
33 |
} |
|
|
34 |
|
|
|
35 |
public function getTokenParsers() |
|
|
36 |
{ |
|
|
37 |
return array( |
|
|
38 |
new AsseticTokenParser($this->factory, 'javascripts', 'js/*.js'), |
|
|
39 |
new AsseticTokenParser($this->factory, 'stylesheets', 'css/*.css'), |
|
|
40 |
new AsseticTokenParser($this->factory, 'image', 'images/*', true), |
|
|
41 |
); |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
public function getFunctions() |
|
|
45 |
{ |
|
|
46 |
$functions = array(); |
|
|
47 |
foreach ($this->functions as $function => $filter) { |
|
|
48 |
$functions[$function] = new AsseticFilterFunction($function); |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
return $functions; |
|
|
52 |
} |
|
|
53 |
|
|
|
54 |
public function getGlobals() |
|
|
55 |
{ |
|
|
56 |
return array( |
|
|
57 |
'assetic' => array('debug' => $this->factory->isDebug()), |
|
|
58 |
); |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
public function getFilterInvoker($function) |
|
|
62 |
{ |
|
|
63 |
return new AsseticFilterInvoker($this->factory, $this->functions[$function]); |
|
|
64 |
} |
|
|
65 |
|
|
|
66 |
public function getName() |
|
|
67 |
{ |
|
|
68 |
return 'assetic'; |
|
|
69 |
} |
|
|
70 |
} |