Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / files / builtin / PhabricatorFilesOnDiskBuiltinFile.php
blobac51e30386d14bbe5fae38d1a681e050c634a9eb
1 <?php
3 final class PhabricatorFilesOnDiskBuiltinFile
4 extends PhabricatorFilesBuiltinFile {
6 private $name;
8 public function setName($name) {
9 $this->name = $name;
10 return $this;
13 public function getName() {
14 if ($this->name === null) {
15 throw new PhutilInvalidStateException('setName');
18 return $this->name;
21 public function getBuiltinDisplayName() {
22 return $this->getName();
25 public function getBuiltinFileKey() {
26 $name = $this->getName();
27 $desc = "disk(name={$name})";
28 $hash = PhabricatorHash::digestToLength($desc, 40);
29 return "builtin:{$hash}";
32 public function loadBuiltinFileData() {
33 $name = $this->getName();
35 $available = $this->getAllBuiltinFiles();
36 if (empty($available[$name])) {
37 throw new Exception(pht('Builtin "%s" does not exist!', $name));
40 return Filesystem::readFile($available[$name]);
43 private function getAllBuiltinFiles() {
44 $root = dirname(phutil_get_library_root('phabricator'));
45 $root = $root.'/resources/builtin/';
47 $map = array();
48 $list = id(new FileFinder($root))
49 ->withType('f')
50 ->withFollowSymlinks(true)
51 ->find();
53 foreach ($list as $file) {
54 $map[$file] = $root.$file;
56 return $map;
59 public function getProjectBuiltinFiles() {
60 $root = dirname(phutil_get_library_root('phabricator'));
61 $root = $root.'/resources/builtin/projects/';
63 $map = array();
64 $list = id(new FileFinder($root))
65 ->withType('f')
66 ->withFollowSymlinks(true)
67 ->find();
69 foreach ($list as $file) {
70 $map[$file] = $root.$file;
72 return $map;