Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/celerity/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. | ||||
| * | * | ||||
| * @group celerity | * @group celerity | ||||
| */ | */ | ||||
| final class CelerityPhabricatorResourceController | final class CelerityPhabricatorResourceController | ||||
| extends CelerityResourceController { | extends CelerityResourceController { | ||||
| private $path; | private $path; | ||||
| private $hash; | private $hash; | ||||
| private $package; | |||||
| protected function getRootDirectory() { | protected function getRootDirectory() { | ||||
| $root = dirname(phutil_get_library_root('phabricator')); | $root = dirname(phutil_get_library_root('phabricator')); | ||||
| return $root.'/webroot/'; | return $root.'/webroot/'; | ||||
| } | } | ||||
| 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->package = !empty($data['package']); | |||||
| } | } | ||||
| public function processRequest() { | public function processRequest() { | ||||
| $package_hash = null; | return $this->serveResource($this->path); | ||||
| if ($this->package) { | |||||
| $package_hash = $this->hash; | |||||
| } | |||||
| return $this->serveResource($this->path, $package_hash); | |||||
| } | } | ||||
| protected function buildResourceTransformer() { | protected function buildResourceTransformer() { | ||||
| $xformer = new CelerityResourceTransformer(); | $xformer = new CelerityResourceTransformer(); | ||||
| $xformer->setMinify( | $xformer->setMinify( | ||||
| !PhabricatorEnv::getEnvConfig('phabricator.developer-mode') && | !PhabricatorEnv::getEnvConfig('phabricator.developer-mode') && | ||||
| PhabricatorEnv::getEnvConfig('celerity.minify')); | PhabricatorEnv::getEnvConfig('celerity.minify')); | ||||
| $xformer->setCelerityMap(CelerityResourceMap::getInstance()); | $xformer->setCelerityMap(CelerityResourceMap::getInstance()); | ||||
| return $xformer; | return $xformer; | ||||
| } | } | ||||
| } | } | ||||