@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Move Celerity gradually toward multiple source support

Summary: Ref T4222. This doesn't actually support multiple sources yet, but moves us closer by getting rid of some dead and exceedingly-singletoney code.

Test Plan: Browsed around, looked at Phame blogs.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7874

+36 -41
+1 -1
src/applications/phame/skins/PhameBasicTemplateBlogSkin.php
··· 29 29 } 30 30 } 31 31 32 - $map = CelerityResourceMap::getInstance(); 32 + $map = CelerityResourceMap::getNamedInstance('phabricator'); 33 33 $resource_symbol = 'syntax-highlighting-css'; 34 34 $resource_uri = $map->getURIForSymbol($resource_symbol); 35 35
+10 -9
src/infrastructure/celerity/CelerityPhabricatorResourceController.php
··· 13 13 private $path; 14 14 private $hash; 15 15 16 - protected function getRootDirectory() { 17 - $root = dirname(phutil_get_library_root('phabricator')); 18 - return $root.'/webroot/'; 16 + public function getCelerityResourceMap() { 17 + return CelerityResourceMap::getNamedInstance('phabricator'); 19 18 } 20 19 21 20 public function willProcessRequest(array $data) { ··· 28 27 } 29 28 30 29 protected function buildResourceTransformer() { 31 - $xformer = new CelerityResourceTransformer(); 32 - $xformer->setMinify( 33 - !PhabricatorEnv::getEnvConfig('phabricator.developer-mode') && 34 - PhabricatorEnv::getEnvConfig('celerity.minify')); 35 - $xformer->setCelerityMap(CelerityResourceMap::getInstance()); 36 - return $xformer; 30 + $minify_on = PhabricatorEnv::getEnvConfig('celerity.minify'); 31 + $developer_on = PhabricatorEnv::getEnvConfig('phabricator.developer-mode'); 32 + 33 + $should_minify = ($minify_on && !$developer_on); 34 + 35 + return id(new CelerityResourceTransformer()) 36 + ->setMinify($should_minify) 37 + ->setCelerityMap($this->getCelerityResourceMap()); 37 38 } 38 39 39 40 }
+1 -3
src/infrastructure/celerity/CelerityResourceController.php
··· 14 14 return false; 15 15 } 16 16 17 - public function getCelerityResourceMap() { 18 - return CelerityResourceMap::getInstance(); 19 - } 17 + abstract public function getCelerityResourceMap(); 20 18 21 19 protected function serveResource($path, $package_hash = null) { 22 20 // Sanity checking to keep this from exposing anything sensitive, since it
+14 -6
src/infrastructure/celerity/CelerityResourceMap.php
··· 8 8 */ 9 9 final class CelerityResourceMap { 10 10 11 - private static $instance; 11 + private static $instances = array(); 12 12 13 13 private $resources; 14 14 private $symbolMap; ··· 37 37 } 38 38 } 39 39 40 - public static function getInstance() { 41 - if (empty(self::$instance)) { 42 - $resources = new CelerityPhabricatorResources(); 43 - self::$instance = new CelerityResourceMap($resources); 40 + public static function getNamedInstance($name) { 41 + if (empty(self::$instances[$name])) { 42 + $resources_list = CelerityPhysicalResources::getAll(); 43 + if (empty($resources_list[$name])) { 44 + throw new Exception( 45 + pht( 46 + 'No resource source exists with name "%s"!', $name)); 47 + } 48 + 49 + $instance = new CelerityResourceMap($resources_list[$name]); 50 + self::$instances[$name] = $instance; 44 51 } 45 - return self::$instance; 52 + 53 + return self::$instances[$name]; 46 54 } 47 55 48 56 public function getPackagedNamesForSymbols(array $symbols) {
-10
src/infrastructure/celerity/CelerityResourceTransformer.php
··· 6 6 final class CelerityResourceTransformer { 7 7 8 8 private $minify; 9 - private $rawResourceMap; 10 9 private $rawURIMap; 11 10 private $celerityMap; 12 11 private $translateURICallback; ··· 19 18 20 19 public function setMinify($minify) { 21 20 $this->minify = $minify; 22 - return $this; 23 - } 24 - 25 - public function setRawResourceMap(array $raw_resource_map) { 26 - $this->rawResourceMap = $raw_resource_map; 27 21 return $this; 28 22 } 29 23 ··· 121 115 if ($this->rawURIMap !== null) { 122 116 if (isset($this->rawURIMap[$uri])) { 123 117 $uri = $this->rawURIMap[$uri]; 124 - } 125 - } else if ($this->rawResourceMap) { 126 - if (isset($this->rawResourceMap[$uri]['uri'])) { 127 - $uri = $this->rawResourceMap[$uri]['uri']; 128 118 } 129 119 } else if ($this->celerityMap) { 130 120 $resource_uri = $this->celerityMap->getURIForName($uri);
+4 -4
src/infrastructure/celerity/CelerityStaticResourceResponse.php
··· 61 61 62 62 private function resolveResources() { 63 63 if ($this->needsResolve) { 64 - $map = CelerityResourceMap::getInstance(); 64 + $map = CelerityResourceMap::getNamedInstance('phabricator'); 65 65 66 66 $symbols = array_keys($this->symbols); 67 67 $this->packaged = $map->getPackagedNamesForSymbols($symbols); ··· 71 71 return $this; 72 72 } 73 73 74 - public function renderSingleResource($symbol) { 75 - $map = CelerityResourceMap::getInstance(); 74 + public function renderSingleResource($symbol, $source_name) { 75 + $map = CelerityResourceMap::getNamedInstance($source_name); 76 76 $packaged = $map->getPackagedNamesForSymbols(array($symbol)); 77 77 return $this->renderPackagedResources($packaged); 78 78 } ··· 236 236 } 237 237 238 238 private function getURI($name) { 239 - $map = CelerityResourceMap::getInstance(); 239 + $map = CelerityResourceMap::getNamedInstance('phabricator'); 240 240 $uri = $map->getURIForName($name); 241 241 242 242 // In developer mode, we dump file modification times into the URI. When a
+2 -4
src/infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php
··· 22 22 ); 23 23 24 24 $xformer = new CelerityResourceTransformer(); 25 - $xformer->setRawResourceMap( 25 + $xformer->setRawURIMap( 26 26 array( 27 - '/rsrc/example.png' => array( 28 - 'uri' => '/res/hash/example.png', 29 - ), 27 + '/rsrc/example.png' => '/res/hash/example.png', 30 28 )); 31 29 $xformer->setMinify($options['minify']); 32 30
+2 -2
src/infrastructure/celerity/api.php
··· 49 49 * 50 50 * @group celerity 51 51 */ 52 - function celerity_get_resource_uri($resource) { 53 - $map = CelerityResourceMap::getInstance(); 52 + function celerity_get_resource_uri($resource, $source = 'phabricator') { 53 + $map = CelerityResourceMap::getNamedInstance($source); 54 54 55 55 $uri = $map->getURIForName($resource); 56 56 if ($uri) {
+1 -1
src/infrastructure/lint/linter/PhabricatorJavelinLinter.php
··· 139 139 } 140 140 } 141 141 142 - $celerity = CelerityResourceMap::getInstance(); 142 + $celerity = CelerityResourceMap::getNamedInstance('phabricator'); 143 143 144 144 $path = preg_replace( 145 145 '@^externals/javelinjs/src/@',
+1 -1
src/view/page/PhabricatorStandardPageView.php
··· 255 255 parent::getHead(), 256 256 phutil_safe_html($monospaced), 257 257 phutil_safe_html($monospaced_win), 258 - $response->renderSingleResource('javelin-magical-init')); 258 + $response->renderSingleResource('javelin-magical-init', 'phabricator')); 259 259 } 260 260 261 261 public function setGlyph($glyph) {