diff --git a/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php b/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php index 8bee67fe8f..a6851b2f9a 100644 --- a/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php +++ b/src/applications/phame/skins/PhameBasicTemplateBlogSkin.php @@ -29,7 +29,7 @@ final class PhameBasicTemplateBlogSkin extends PhameBasicBlogSkin { } } - $map = CelerityResourceMap::getInstance(); + $map = CelerityResourceMap::getNamedInstance('phabricator'); $resource_symbol = 'syntax-highlighting-css'; $resource_uri = $map->getURIForSymbol($resource_symbol); diff --git a/src/infrastructure/celerity/CelerityPhabricatorResourceController.php b/src/infrastructure/celerity/CelerityPhabricatorResourceController.php index ab8aa49d1a..1f258cea8c 100644 --- a/src/infrastructure/celerity/CelerityPhabricatorResourceController.php +++ b/src/infrastructure/celerity/CelerityPhabricatorResourceController.php @@ -13,9 +13,8 @@ final class CelerityPhabricatorResourceController private $path; private $hash; - protected function getRootDirectory() { - $root = dirname(phutil_get_library_root('phabricator')); - return $root.'/webroot/'; + public function getCelerityResourceMap() { + return CelerityResourceMap::getNamedInstance('phabricator'); } public function willProcessRequest(array $data) { @@ -28,12 +27,14 @@ final class CelerityPhabricatorResourceController } protected function buildResourceTransformer() { - $xformer = new CelerityResourceTransformer(); - $xformer->setMinify( - !PhabricatorEnv::getEnvConfig('phabricator.developer-mode') && - PhabricatorEnv::getEnvConfig('celerity.minify')); - $xformer->setCelerityMap(CelerityResourceMap::getInstance()); - return $xformer; + $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) + ->setCelerityMap($this->getCelerityResourceMap()); } } diff --git a/src/infrastructure/celerity/CelerityResourceController.php b/src/infrastructure/celerity/CelerityResourceController.php index f192c049b5..17b8403276 100644 --- a/src/infrastructure/celerity/CelerityResourceController.php +++ b/src/infrastructure/celerity/CelerityResourceController.php @@ -14,9 +14,7 @@ abstract class CelerityResourceController extends PhabricatorController { return false; } - public function getCelerityResourceMap() { - return CelerityResourceMap::getInstance(); - } + abstract public function getCelerityResourceMap(); protected function serveResource($path, $package_hash = null) { // Sanity checking to keep this from exposing anything sensitive, since it diff --git a/src/infrastructure/celerity/CelerityResourceMap.php b/src/infrastructure/celerity/CelerityResourceMap.php index 6d307b2eaa..ebaa4fb9a6 100644 --- a/src/infrastructure/celerity/CelerityResourceMap.php +++ b/src/infrastructure/celerity/CelerityResourceMap.php @@ -8,7 +8,7 @@ */ final class CelerityResourceMap { - private static $instance; + private static $instances = array(); private $resources; private $symbolMap; @@ -37,12 +37,20 @@ final class CelerityResourceMap { } } - public static function getInstance() { - if (empty(self::$instance)) { - $resources = new CelerityPhabricatorResources(); - self::$instance = new CelerityResourceMap($resources); + public static function getNamedInstance($name) { + if (empty(self::$instances[$name])) { + $resources_list = CelerityPhysicalResources::getAll(); + if (empty($resources_list[$name])) { + throw new Exception( + pht( + 'No resource source exists with name "%s"!', $name)); + } + + $instance = new CelerityResourceMap($resources_list[$name]); + self::$instances[$name] = $instance; } - return self::$instance; + + return self::$instances[$name]; } public function getPackagedNamesForSymbols(array $symbols) { diff --git a/src/infrastructure/celerity/CelerityResourceTransformer.php b/src/infrastructure/celerity/CelerityResourceTransformer.php index 846d8b5e89..52b9083b82 100644 --- a/src/infrastructure/celerity/CelerityResourceTransformer.php +++ b/src/infrastructure/celerity/CelerityResourceTransformer.php @@ -6,7 +6,6 @@ final class CelerityResourceTransformer { private $minify; - private $rawResourceMap; private $rawURIMap; private $celerityMap; private $translateURICallback; @@ -22,11 +21,6 @@ final class CelerityResourceTransformer { return $this; } - public function setRawResourceMap(array $raw_resource_map) { - $this->rawResourceMap = $raw_resource_map; - return $this; - } - public function setCelerityMap(CelerityResourceMap $celerity_map) { $this->celerityMap = $celerity_map; return $this; @@ -122,10 +116,6 @@ final class CelerityResourceTransformer { if (isset($this->rawURIMap[$uri])) { $uri = $this->rawURIMap[$uri]; } - } else if ($this->rawResourceMap) { - if (isset($this->rawResourceMap[$uri]['uri'])) { - $uri = $this->rawResourceMap[$uri]['uri']; - } } else if ($this->celerityMap) { $resource_uri = $this->celerityMap->getURIForName($uri); if ($resource_uri) { diff --git a/src/infrastructure/celerity/CelerityStaticResourceResponse.php b/src/infrastructure/celerity/CelerityStaticResourceResponse.php index ee55074ac4..b52274f323 100644 --- a/src/infrastructure/celerity/CelerityStaticResourceResponse.php +++ b/src/infrastructure/celerity/CelerityStaticResourceResponse.php @@ -61,7 +61,7 @@ final class CelerityStaticResourceResponse { private function resolveResources() { if ($this->needsResolve) { - $map = CelerityResourceMap::getInstance(); + $map = CelerityResourceMap::getNamedInstance('phabricator'); $symbols = array_keys($this->symbols); $this->packaged = $map->getPackagedNamesForSymbols($symbols); @@ -71,8 +71,8 @@ final class CelerityStaticResourceResponse { return $this; } - public function renderSingleResource($symbol) { - $map = CelerityResourceMap::getInstance(); + public function renderSingleResource($symbol, $source_name) { + $map = CelerityResourceMap::getNamedInstance($source_name); $packaged = $map->getPackagedNamesForSymbols(array($symbol)); return $this->renderPackagedResources($packaged); } @@ -236,7 +236,7 @@ final class CelerityStaticResourceResponse { } private function getURI($name) { - $map = CelerityResourceMap::getInstance(); + $map = CelerityResourceMap::getNamedInstance('phabricator'); $uri = $map->getURIForName($name); // In developer mode, we dump file modification times into the URI. When a diff --git a/src/infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php b/src/infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php index 883e415540..f23862b8d0 100644 --- a/src/infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php +++ b/src/infrastructure/celerity/__tests__/CelerityResourceTransformerTestCase.php @@ -22,11 +22,9 @@ final class CelerityResourceTransformerTestCase extends PhabricatorTestCase { ); $xformer = new CelerityResourceTransformer(); - $xformer->setRawResourceMap( + $xformer->setRawURIMap( array( - '/rsrc/example.png' => array( - 'uri' => '/res/hash/example.png', - ), + '/rsrc/example.png' => '/res/hash/example.png', )); $xformer->setMinify($options['minify']); diff --git a/src/infrastructure/celerity/api.php b/src/infrastructure/celerity/api.php index 1f5346df90..8b04b49fd3 100644 --- a/src/infrastructure/celerity/api.php +++ b/src/infrastructure/celerity/api.php @@ -49,8 +49,8 @@ function celerity_generate_unique_node_id() { * * @group celerity */ -function celerity_get_resource_uri($resource) { - $map = CelerityResourceMap::getInstance(); +function celerity_get_resource_uri($resource, $source = 'phabricator') { + $map = CelerityResourceMap::getNamedInstance($source); $uri = $map->getURIForName($resource); if ($uri) { diff --git a/src/infrastructure/lint/linter/PhabricatorJavelinLinter.php b/src/infrastructure/lint/linter/PhabricatorJavelinLinter.php index 24003939f0..b979c9e87b 100644 --- a/src/infrastructure/lint/linter/PhabricatorJavelinLinter.php +++ b/src/infrastructure/lint/linter/PhabricatorJavelinLinter.php @@ -139,7 +139,7 @@ final class PhabricatorJavelinLinter extends ArcanistLinter { } } - $celerity = CelerityResourceMap::getInstance(); + $celerity = CelerityResourceMap::getNamedInstance('phabricator'); $path = preg_replace( '@^externals/javelinjs/src/@', diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php index ee639564b2..d31c3567b8 100644 --- a/src/view/page/PhabricatorStandardPageView.php +++ b/src/view/page/PhabricatorStandardPageView.php @@ -255,7 +255,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView { parent::getHead(), phutil_safe_html($monospaced), phutil_safe_html($monospaced_win), - $response->renderSingleResource('javelin-magical-init')); + $response->renderSingleResource('javelin-magical-init', 'phabricator')); } public function setGlyph($glyph) {