Make lookupSymbolInformation() a private API on CelerityResourceMap

Summary: Ref T4222. Same deal as D7867, but for this other super nebulous "return a blob of stuff" method.

Test Plan: Regenerated map, browsed around, etc.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7868
This commit is contained in:
epriestley 2013-12-31 18:03:09 -08:00
parent 8aaf5084e8
commit 60ff29ed06
4 changed files with 64 additions and 14 deletions

View file

@ -30,14 +30,15 @@ final class PhameBasicTemplateBlogSkin extends PhameBasicBlogSkin {
} }
$map = CelerityResourceMap::getInstance(); $map = CelerityResourceMap::getInstance();
$symbol_info = $map->lookupSymbolInformation('syntax-highlighting-css'); $resource_symbol = 'syntax-highlighting-css';
$resource_uri = $map->getFullyQualifiedURIForSymbol($resource_symbol);
$this->cssResources[] = phutil_tag( $this->cssResources[] = phutil_tag(
'link', 'link',
array( array(
'rel' => 'stylesheet', 'rel' => 'stylesheet',
'type' => 'text/css', 'type' => 'text/css',
'href' => PhabricatorEnv::getCDNURI($symbol_info['uri']), 'href' => $resource_uri,
)); ));
$this->cssResources = phutil_implode_html("\n", $this->cssResources); $this->cssResources = phutil_implode_html("\n", $this->cssResources);

View file

@ -104,7 +104,7 @@ final class CelerityResourceMap {
return $paths; return $paths;
} }
public function lookupSymbolInformation($symbol) { private function lookupSymbolInformation($symbol) {
return idx($this->resourceMap, $symbol); return idx($this->resourceMap, $symbol);
} }
@ -120,12 +120,46 @@ final class CelerityResourceMap {
} }
/**
* Get the epoch timestamp of the last modification time of a symbol.
*
* @param string Resource symbol to lookup.
* @return int Epoch timestamp of last resource modification.
*/
public function getModifiedTimeForSymbol($symbol) {
$info = $this->lookupSymbolInformation($symbol);
if ($info) {
$root = dirname(phutil_get_library_root('phabricator')).'/webroot';
return (int)filemtime($root.$info['disk']);
}
return 0;
}
/**
* Return the fully-qualified, absolute URI for the resource associated with
* a symbol. This method is fairly low-level and ignores packaging.
*
* @param string Resource symbol to lookup.
* @return string|null Fully-qualified resource URI, or null if the symbol
* is unknown.
*/
public function getFullyQualifiedURIForSymbol($symbol) {
$info = $this->lookupSymbolInformation($symbol);
if ($info) {
return idx($info, 'uri');
}
return null;
}
/** /**
* Return the fully-qualified, absolute URI for the resource associated with * Return the fully-qualified, absolute URI for the resource associated with
* a resource name. This method is fairly low-level and ignores packaging. * a resource name. This method is fairly low-level and ignores packaging.
* *
* @param string Resource name to lookup. * @param string Resource name to lookup.
* @return string Fully-qualified resource URI. * @return string|null Fully-qualified resource URI, or null if the name
* is unknown.
*/ */
public function getFullyQualifiedURIForName($name) { public function getFullyQualifiedURIForName($name) {
$info = $this->lookupFileInformation($name); $info = $this->lookupFileInformation($name);
@ -140,7 +174,8 @@ final class CelerityResourceMap {
* Return the resource symbols required by a named resource. * Return the resource symbols required by a named resource.
* *
* @param string Resource name to lookup. * @param string Resource name to lookup.
* @return list<string> List of required symbols. * @return list<string>|null List of required symbols, or null if the name
* is unknown.
*/ */
public function getRequiredSymbolsForName($name) { public function getRequiredSymbolsForName($name) {
$info = $this->lookupFileInformation($name); $info = $this->lookupFileInformation($name);
@ -151,4 +186,19 @@ final class CelerityResourceMap {
} }
/**
* Return the resource name for a given symbol.
*
* @param string Resource symbol to lookup.
* @return string|null Resource name, or null if the symbol is unknown.
*/
public function getResourceNameForSymbol($symbol) {
$info = $this->lookupSymbolInformation($symbol);
if ($info) {
return idx($info, 'disk');
}
return null;
}
} }

View file

@ -249,8 +249,7 @@ final class CelerityStaticResourceResponse {
$mtime = 0; $mtime = 0;
foreach ($resource['symbols'] as $symbol) { foreach ($resource['symbols'] as $symbol) {
$map = CelerityResourceMap::getInstance(); $map = CelerityResourceMap::getInstance();
$symbol_info = $map->lookupSymbolInformation($symbol); $mtime = max($mtime, $map->getModifiedTimeForSymbol($symbol));
$mtime = max($mtime, (int)filemtime($root.$symbol_info['disk']));
} }
} }

View file

@ -153,24 +153,24 @@ final class PhabricatorJavelinLinter extends ArcanistLinter {
$requires = array(); $requires = array();
} }
foreach ($requires as $key => $symbol_name) { foreach ($requires as $key => $requires_symbol) {
$symbol_info = $celerity->lookupSymbolInformation($symbol_name); $requires_name = $celerity->getResourceNameForSymbol($requires_symbol);
if (!$symbol_info) { if ($requires_name === null) {
$this->raiseLintAtLine( $this->raiseLintAtLine(
0, 0,
0, 0,
self::LINT_UNKNOWN_DEPENDENCY, self::LINT_UNKNOWN_DEPENDENCY,
"This file @requires component '{$symbol_name}', but it does not ". "This file @requires component '{$requires_symbol}', but it does ".
"exist. You may need to rebuild the Celerity map."); "not exist. You may need to rebuild the Celerity map.");
unset($requires[$key]); unset($requires[$key]);
continue; continue;
} }
if (preg_match('/\\.css$/', $symbol_info['disk'])) { if (preg_match('/\\.css$/', $requires_name)) {
// If JS requires CSS, just assume everything is fine. // If JS requires CSS, just assume everything is fine.
unset($requires[$key]); unset($requires[$key]);
} else { } else {
$symbol_path = 'webroot'.$symbol_info['disk']; $symbol_path = 'webroot'.$requires_name;
list($ignored, $req_install) = $this->getUsedAndInstalledSymbolsForPath( list($ignored, $req_install) = $this->getUsedAndInstalledSymbolsForPath(
$symbol_path); $symbol_path);
if (array_intersect_key($req_install, $external_classes)) { if (array_intersect_key($req_install, $external_classes)) {