Differential D13363 Diff 32360 src/applications/celerity/controller/CelerityPhabricatorResourceController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/celerity/controller/CelerityPhabricatorResourceController.php
| <?php | <?php | ||||
| /** | /** | ||||
| * Delivers CSS and JS resources to the browser. This controller handles all | * Delivers CSS and JS resources to the browser. This controller handles all | ||||
| * `/res/` requests, and manages caching, package construction, and resource | * `/res/` requests, and manages caching, package construction, and resource | ||||
| * preprocessing. | * preprocessing. | ||||
| */ | */ | ||||
| final class CelerityPhabricatorResourceController | final class CelerityPhabricatorResourceController | ||||
| extends CelerityResourceController { | extends CelerityResourceController { | ||||
| private $path; | private $path; | ||||
| private $hash; | private $hash; | ||||
| private $library; | private $library; | ||||
| private $postprocessorKey; | |||||
| public function getCelerityResourceMap() { | public function getCelerityResourceMap() { | ||||
| return CelerityResourceMap::getNamedInstance($this->library); | return CelerityResourceMap::getNamedInstance($this->library); | ||||
| } | } | ||||
| public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
| $this->path = $data['path']; | $this->path = $data['path']; | ||||
| $this->hash = $data['hash']; | $this->hash = $data['hash']; | ||||
| $this->library = $data['library']; | $this->library = $data['library']; | ||||
| $this->postprocessorKey = idx($data, 'postprocessor'); | |||||
| } | } | ||||
| public function processRequest() { | public function processRequest() { | ||||
| // Check that the resource library exists before trying to serve resources | // Check that the resource library exists before trying to serve resources | ||||
| // from it. | // from it. | ||||
| try { | try { | ||||
| $this->getCelerityResourceMap(); | $this->getCelerityResourceMap(); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| return new Aphront400Response(); | return new Aphront400Response(); | ||||
| } | } | ||||
| return $this->serveResource($this->path); | return $this->serveResource($this->path); | ||||
| } | } | ||||
| protected function buildResourceTransformer() { | protected function buildResourceTransformer() { | ||||
| $minify_on = PhabricatorEnv::getEnvConfig('celerity.minify'); | $minify_on = PhabricatorEnv::getEnvConfig('celerity.minify'); | ||||
| $developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); | $developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); | ||||
| $should_minify = ($minify_on && !$developer_on); | $should_minify = ($minify_on && !$developer_on); | ||||
| return id(new CelerityResourceTransformer()) | return id(new CelerityResourceTransformer()) | ||||
| ->setMinify($should_minify) | ->setMinify($should_minify) | ||||
| ->setPostprocessorKey($this->postprocessorKey) | |||||
| ->setCelerityMap($this->getCelerityResourceMap()); | ->setCelerityMap($this->getCelerityResourceMap()); | ||||
| } | } | ||||
| protected function getCacheKey($path) { | |||||
| return parent::getCacheKey($path.';'.$this->postprocessorKey); | |||||
| } | |||||
| } | } | ||||