@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Defines the location of static resources on disk.
5 */
6abstract 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 'woff2',
38 'mp3',
39 'ico',
40 );
41 }
42
43 protected function getTextFileSuffixes() {
44 return array(
45 'js',
46 'css',
47 );
48 }
49
50 private function findResourcesWithSuffixes(array $suffixes) {
51 $root = $this->getPathToResources();
52
53 $finder = id(new FileFinder($root))
54 ->withType('f')
55 ->withFollowSymlinks(true)
56 ->setGenerateChecksums(true);
57
58 foreach ($suffixes as $suffix) {
59 $finder->withSuffix($suffix);
60 }
61
62 $raw_files = $finder->find();
63
64 $results = array();
65 foreach ($raw_files as $path => $hash) {
66 $readable = Filesystem::readablePath($path, $root);
67 $results[$readable] = $hash;
68 }
69
70 return $results;
71 }
72
73}