-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextension.driver.php
83 lines (72 loc) · 2.32 KB
/
extension.driver.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once('lib/folder_iterator_factory.php');
use symphony\extensions\static_asset_versioning\FolderIteratorFactory as FolderIteratorFactory;
/**
* extension_static_asset_versioning
*
* @package static_asset_versioning
* @author Huib Keemink
**/
class extension_static_asset_versioning extends Extension
{
public function getSubscribedDelegates()
{
return array(
array(
'page' => '/frontend/',
'delegate' => 'FrontendOutputPreGenerate',
'callback' => 'addVersionData'
),
);
}
public function addVersionData($context)
{
$start = precision_timer();
//var_dump($context['xml']);
$factory = new FolderIteratorFactory;
$watch_dirs = array(
'js' => WORKSPACE . '/js',
'css' => WORKSPACE . '/css',
);
$extensions = array(
'css',
'js'
);
$watch_dirs = array_map('realpath', $watch_dirs);
$directories = $factory->build(
$watch_dirs,
$extensions
);
$data = array();
foreach ($directories as $file) {
$folder_name = array_search(dirname($file->getRealPath()), $watch_dirs);
if (!is_string($folder_name)) {
throw new Exception('Please set a name for each directory I need to track');
}
$data[$folder_name][] = array(
$file->getBaseName()
=>
substr(
sha1_file(
$file->getRealPath()
),
0,
9
)
);
}
//die();
$assets = new XMLElement('assets');
foreach ($data as $dir => $files) {
$directory = new XMLElement($dir);
foreach ($files as $file) {
$file_element = new XMLElement(key($file), current($file));
$directory->appendChild($file_element);
}
$assets->appendChild($directory);
}
$context['xml'] = str_replace('</params>', '</params>' . "\n" . $assets->generate(true, 1), $context['xml']);
Symphony::Profiler()->seed($start);
Symphony::Profiler()->sample('Asset Hashes Generated', PROFILE_LAP);
}
}