Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/files/builtin/PhabricatorFilesOnDiskBuiltinFile.php
12242 views
1
<?php
2
3
final class PhabricatorFilesOnDiskBuiltinFile
4
extends PhabricatorFilesBuiltinFile {
5
6
private $name;
7
8
public function setName($name) {
9
$this->name = $name;
10
return $this;
11
}
12
13
public function getName() {
14
if ($this->name === null) {
15
throw new PhutilInvalidStateException('setName');
16
}
17
18
return $this->name;
19
}
20
21
public function getBuiltinDisplayName() {
22
return $this->getName();
23
}
24
25
public function getBuiltinFileKey() {
26
$name = $this->getName();
27
$desc = "disk(name={$name})";
28
$hash = PhabricatorHash::digestToLength($desc, 40);
29
return "builtin:{$hash}";
30
}
31
32
public function loadBuiltinFileData() {
33
$name = $this->getName();
34
35
$available = $this->getAllBuiltinFiles();
36
if (empty($available[$name])) {
37
throw new Exception(pht('Builtin "%s" does not exist!', $name));
38
}
39
40
return Filesystem::readFile($available[$name]);
41
}
42
43
private function getAllBuiltinFiles() {
44
$root = dirname(phutil_get_library_root('phabricator'));
45
$root = $root.'/resources/builtin/';
46
47
$map = array();
48
$list = id(new FileFinder($root))
49
->withType('f')
50
->withFollowSymlinks(true)
51
->find();
52
53
foreach ($list as $file) {
54
$map[$file] = $root.$file;
55
}
56
return $map;
57
}
58
59
public function getProjectBuiltinFiles() {
60
$root = dirname(phutil_get_library_root('phabricator'));
61
$root = $root.'/resources/builtin/projects/';
62
63
$map = array();
64
$list = id(new FileFinder($root))
65
->withType('f')
66
->withFollowSymlinks(true)
67
->find();
68
69
foreach ($list as $file) {
70
$map[$file] = $root.$file;
71
}
72
return $map;
73
}
74
75
}
76
77