forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorFilesOnDiskBuiltinFile.php
56 lines (42 loc) · 1.21 KB
/
PhabricatorFilesOnDiskBuiltinFile.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
<?php
final class PhabricatorFilesOnDiskBuiltinFile
extends PhabricatorFilesBuiltinFile {
private $name;
public function setName($name) {
$this->name = $name;
return $this;
}
public function getName() {
if ($this->name === null) {
throw new PhutilInvalidStateException('setName');
}
return $this->name;
}
public function getBuiltinDisplayName() {
return $this->getName();
}
public function getBuiltinFileKey() {
$name = $this->getName();
$desc = "disk(name={$name})";
$hash = PhabricatorHash::digestToLength($desc, 40);
return "builtin:{$hash}";
}
public function loadBuiltinFileData() {
$name = $this->getName();
$available = $this->getAllBuiltinFiles();
if (empty($available[$name])) {
throw new Exception(pht('Builtin "%s" does not exist!', $name));
}
return Filesystem::readFile($available[$name]);
}
private function getAllBuiltinFiles() {
$root = dirname(phutil_get_library_root('phabricator'));
$root = $root.'/resources/builtin/';
$map = array();
$list = Filesystem::listDirectory($root, $include_hidden = false);
foreach ($list as $file) {
$map[$file] = $root.$file;
}
return $map;
}
}