mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-08 22:01:03 +01:00
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
This commit is contained in:
parent
d8c11a2106
commit
5173b4954d
10 changed files with 36 additions and 41 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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']);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -139,7 +139,7 @@ final class PhabricatorJavelinLinter extends ArcanistLinter {
|
|||
}
|
||||
}
|
||||
|
||||
$celerity = CelerityResourceMap::getInstance();
|
||||
$celerity = CelerityResourceMap::getNamedInstance('phabricator');
|
||||
|
||||
$path = preg_replace(
|
||||
'@^externals/javelinjs/src/@',
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue