1 | <?php |
||
13 | class AssetMacro extends MacroSet |
||
14 | { |
||
15 | |||
16 | const VERSIONS_AUTODETECT = NULL; |
||
17 | |||
18 | const VERSIONS_AUTODETECT_PATHS = [ |
||
19 | 'busters.json', |
||
20 | 'versions.json', |
||
21 | 'rev-manifest.json' |
||
22 | ]; |
||
23 | |||
24 | const VERSIONS_PROVIDER = 'assetMacroVersions'; |
||
25 | |||
26 | const WWW_DIR_PROVIDER = 'assetMacroWwwDir'; |
||
27 | |||
28 | /** |
||
29 | * @param Latte\Compiler $compiler |
||
30 | */ |
||
31 | public static function install(Latte\Compiler $compiler) |
||
36 | |||
37 | |||
38 | /** |
||
39 | * @param Latte\MacroNode $node |
||
40 | * @param Latte\PhpWriter $writer |
||
41 | * @return string |
||
42 | */ |
||
43 | public function macroAsset(Latte\MacroNode $node, Latte\PhpWriter $writer) |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Append version (from JSON file or versions array) to asset relative path. |
||
58 | * |
||
59 | * @param string $relativePath |
||
60 | * @param string|array $assetVersions |
||
61 | * @param string $wwwDir |
||
62 | * @return string |
||
63 | */ |
||
64 | public static function appendVersion($relativePath, $assetVersions, $wwwDir) |
||
81 | |||
82 | |||
83 | /** |
||
84 | * Get asset version hash. |
||
85 | * If the record can not be found, then version is 'unknown'. |
||
86 | * |
||
87 | * @param string|array $assetsVersions |
||
88 | * @param string $absolutePath |
||
89 | * @return mixed|string |
||
90 | */ |
||
91 | private static function getAssetVersion($assetsVersions, $absolutePath) |
||
110 | |||
111 | |||
112 | /** |
||
113 | * Autodetect version file path. |
||
114 | * It searches the asset directory and all parent directories up to www dir for files: |
||
115 | * - busters.json |
||
116 | * - versions.json |
||
117 | * - rev-manifest.json |
||
118 | * It is also possible to use asset name with the extension JSON (eg. some/path/main.js.json). |
||
119 | * |
||
120 | * @param string $absolutePath |
||
121 | * @param string $wwwDir |
||
122 | * @return mixed|string |
||
123 | */ |
||
124 | private static function autodetectVersionsFile($absolutePath, $wwwDir) |
||
154 | |||
155 | } |
||
156 |