Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/celerity/controller/CelerityPhabricatorResourceController.php
12256 views
1
<?php
2
3
/**
4
* Delivers CSS and JS resources to the browser. This controller handles all
5
* `/res/` requests, and manages caching, package construction, and resource
6
* preprocessing.
7
*/
8
final class CelerityPhabricatorResourceController
9
extends CelerityResourceController {
10
11
private $path;
12
private $hash;
13
private $library;
14
private $postprocessorKey;
15
16
public function getCelerityResourceMap() {
17
return CelerityResourceMap::getNamedInstance($this->library);
18
}
19
20
public function handleRequest(AphrontRequest $request) {
21
$this->path = $request->getURIData('path');
22
$this->hash = $request->getURIData('hash');
23
$this->library = $request->getURIData('library');
24
$this->postprocessorKey = $request->getURIData('postprocessor');
25
26
// Check that the resource library exists before trying to serve resources
27
// from it.
28
try {
29
$this->getCelerityResourceMap();
30
} catch (Exception $ex) {
31
return new Aphront400Response();
32
}
33
34
return $this->serveResource(
35
array(
36
'path' => $this->path,
37
'hash' => $this->hash,
38
));
39
}
40
41
protected function buildResourceTransformer() {
42
$developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
43
$should_minify = !$developer_on;
44
45
return id(new CelerityResourceTransformer())
46
->setMinify($should_minify)
47
->setPostprocessorKey($this->postprocessorKey)
48
->setCelerityMap($this->getCelerityResourceMap());
49
}
50
51
protected function getCacheKey($path) {
52
return parent::getCacheKey($path.';'.$this->postprocessorKey);
53
}
54
55
}
56
57