forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCelerityPhabricatorResourceController.php
53 lines (42 loc) · 1.55 KB
/
CelerityPhabricatorResourceController.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
<?php
/**
* Delivers CSS and JS resources to the browser. This controller handles all
* `/res/` requests, and manages caching, package construction, and resource
* preprocessing.
*/
final class CelerityPhabricatorResourceController
extends CelerityResourceController {
private $path;
private $hash;
private $library;
private $postprocessorKey;
public function getCelerityResourceMap() {
return CelerityResourceMap::getNamedInstance($this->library);
}
public function handleRequest(AphrontRequest $request) {
$this->path = $request->getURIData('path');
$this->hash = $request->getURIData('hash');
$this->library = $request->getURIData('library');
$this->postprocessorKey = $request->getURIData('postprocessor');
// Check that the resource library exists before trying to serve resources
// from it.
try {
$this->getCelerityResourceMap();
} catch (Exception $ex) {
return new Aphront400Response();
}
return $this->serveResource($this->path);
}
protected function buildResourceTransformer() {
$minify_on = PhabricatorEnv::getEnvConfig('celerity.minify');
$developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode');
$should_minify = ($minify_on && !$developer_on);
return id(new CelerityResourceTransformer())
->setMinify($should_minify)
->setPostprocessorKey($this->postprocessorKey)
->setCelerityMap($this->getCelerityResourceMap());
}
protected function getCacheKey($path) {
return parent::getCacheKey($path.';'.$this->postprocessorKey);
}
}