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 array |
||
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 array $assets The array of assets and rev'd assets |
||
53 | * @param bool $minified Whether to search for minified rev'd assets |
||
54 | */ |
||
55 | 24 | public function __construct(array $assets, $minified = true) |
|
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | 9 | public function getFilters() |
|
70 | |||
71 | /** |
||
72 | * Gets the rev'd asset, |
||
73 | * |
||
74 | * @param \Twig_Environment $env The twig environment |
||
75 | * @param string $asset The asset string to rev |
||
76 | * |
||
77 | * @return string The rev'd asset if available, else the original asset |
||
78 | */ |
||
79 | 24 | public function assetRev(\Twig_Environment $env, $asset) |
|
89 | |||
90 | /** |
||
91 | * Gets the minified asset |
||
92 | * |
||
93 | * @param \Twig_Environment $env The twig environment |
||
94 | * @param array $pathinfo The pathinfo for the asset |
||
95 | * |
||
96 | * @return bool|string The minified rev'd asset if available, else false |
||
97 | */ |
||
98 | 18 | public function minify($env, $pathinfo) |
|
115 | |||
116 | /** |
||
117 | * Returns the name of the extension. |
||
118 | * |
||
119 | * @return string The extension name |
||
120 | */ |
||
121 | 24 | public function getName() |
|
125 | } |
||
126 |