Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/celerity/resources/CelerityResourcesOnDisk.php
12256 views
1
<?php
2
3
/**
4
* Defines the location of static resources on disk.
5
*/
6
abstract class CelerityResourcesOnDisk extends CelerityPhysicalResources {
7
8
abstract public function getPathToResources();
9
10
private function getPathToResource($name) {
11
return $this->getPathToResources().DIRECTORY_SEPARATOR.$name;
12
}
13
14
public function getResourceData($name) {
15
return Filesystem::readFile($this->getPathToResource($name));
16
}
17
18
public function findBinaryResources() {
19
return $this->findResourcesWithSuffixes($this->getBinaryFileSuffixes());
20
}
21
22
public function findTextResources() {
23
return $this->findResourcesWithSuffixes($this->getTextFileSuffixes());
24
}
25
26
public function getResourceModifiedTime($name) {
27
return (int)filemtime($this->getPathToResource($name));
28
}
29
30
protected function getBinaryFileSuffixes() {
31
return array(
32
'png',
33
'jpg',
34
'gif',
35
'swf',
36
'svg',
37
'woff',
38
'woff2',
39
'ttf',
40
'eot',
41
'mp3',
42
'ico',
43
);
44
}
45
46
protected function getTextFileSuffixes() {
47
return array(
48
'js',
49
'css',
50
);
51
}
52
53
private function findResourcesWithSuffixes(array $suffixes) {
54
$root = $this->getPathToResources();
55
56
$finder = id(new FileFinder($root))
57
->withType('f')
58
->withFollowSymlinks(true)
59
->setGenerateChecksums(true);
60
61
foreach ($suffixes as $suffix) {
62
$finder->withSuffix($suffix);
63
}
64
65
$raw_files = $finder->find();
66
67
$results = array();
68
foreach ($raw_files as $path => $hash) {
69
$readable = Filesystem::readablePath($path, $root);
70
$results[$readable] = $hash;
71
}
72
73
return $results;
74
}
75
76
}
77
78