-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathElixirHelper.php
43 lines (33 loc) · 1.07 KB
/
ElixirHelper.php
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
<?php
App::uses('AppHelper', 'View/Helper');
class ElixirHelper extends AppHelper {
/**
* Get the path to a versioned Elixir file.
*
* @param string $file
* @param string $buildDirectory
* @return string
*
* @throws \InvalidArgumentException
*/
function version($file, $buildDirectory = 'build')
{
static $manifest = [];
static $manifestPath;
if (empty($manifest) || $manifestPath !== $buildDirectory) {
$path = WWW_ROOT.$buildDirectory.'/rev-manifest.json';
if (file_exists($path)) {
$manifest = json_decode(file_get_contents($path), true);
$manifestPath = $buildDirectory;
}
}
if (isset($manifest[$file])) {
return '/'.trim($buildDirectory.'/'.$manifest[$file], '/');
}
$unversioned = WWW_ROOT.$file;
if (file_exists($unversioned)) {
return '/'.trim($file, '/');
}
throw new InvalidArgumentException("File {$file} not defined in asset manifest.");
}
}