1 | <?php |
||
26 | class TwigAssetRevExtension extends \Twig_Extension |
||
27 | { |
||
28 | /** |
||
29 | * The file extensions to check if there is a minified version |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | private static $minify_exts = array('css', 'js'); |
||
34 | |||
35 | /** |
||
36 | * The array of assets rev, raw_asset => rev_asset |
||
37 | * |
||
38 | * @var mixed |
||
39 | */ |
||
40 | private $assets; |
||
41 | |||
42 | /** |
||
43 | * Whether to search for minified rev'd versions of the assets |
||
44 | * |
||
45 | * @var bool |
||
46 | */ |
||
47 | private $minified; |
||
48 | |||
49 | /** |
||
50 | * The TwigAssetRevExtension constructor |
||
51 | * |
||
52 | * @param mixed $assets The array of assets and rev'd assets |
||
53 | * @param bool $minified Whether to search for minified rev'd assets |
||
54 | */ |
||
55 | 27 | public function __construct($assets, $minified = true) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 12 | public function getFilters() |
|
74 | |||
75 | /** |
||
76 | * Gets the rev'd asset, |
||
77 | * |
||
78 | * @param \Twig_Environment $env The twig environment |
||
79 | * @param string $asset The asset string to rev |
||
80 | * |
||
81 | * @return string The rev'd asset if available, else the original asset |
||
82 | */ |
||
83 | 27 | public function assetRev(\Twig_Environment $env, $asset) |
|
93 | |||
94 | /** |
||
95 | * Gets the minified asset |
||
96 | * |
||
97 | * @param \Twig_Environment $env The twig environment |
||
98 | * @param array $pathinfo The pathinfo for the asset |
||
99 | * |
||
100 | * @return bool|string The minified rev'd asset if available, else false |
||
101 | */ |
||
102 | 21 | public function minify($env, $pathinfo) |
|
118 | |||
119 | /** |
||
120 | * Returns the name of the extension. |
||
121 | * |
||
122 | * @return string The extension name |
||
123 | */ |
||
124 | 27 | public function getName() |
|
128 | } |
||
129 |