1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Improve package resolution APIs on CelerityResourceMap

Summary:
Ref T4222. A few diffs from now, `CelerityResourceMap` will have a `CelerityResources` inside of it:

  - Rename `resolvePackage()` to `getResourceNamesForPackageHash()`. This isn't a functional change, it's just making it clear what it does.
  - Add `getResourceDataForName()`, to push details about storage into `CelerityResources`.

Test Plan: Reloaded a bunch of pages, rebuilt map.

Reviewers: btrahan, hach-que

Reviewed By: hach-que

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7869
This commit is contained in:
epriestley 2013-12-31 18:03:17 -08:00
parent 60ff29ed06
commit 59ad78d4ab
2 changed files with 14 additions and 13 deletions

View file

@ -16,10 +16,6 @@ abstract class CelerityResourceController extends PhabricatorController {
return false; return false;
} }
private function getDiskPath($to_resource = null) {
return $this->getRootDirectory().$to_resource;
}
protected function serveResource($path, $package_hash = null) { protected function serveResource($path, $package_hash = null) {
// Sanity checking to keep this from exposing anything sensitive, since it // Sanity checking to keep this from exposing anything sensitive, since it
// ultimately boils down to disk reads. // ultimately boils down to disk reads.
@ -41,18 +37,18 @@ abstract class CelerityResourceController extends PhabricatorController {
return $this->makeResponseCacheable(new Aphront304Response()); return $this->makeResponseCacheable(new Aphront304Response());
} }
$map = CelerityResourceMap::getInstance();
if ($package_hash) { if ($package_hash) {
$map = CelerityResourceMap::getInstance(); $resource_names = $map->getResourceNamesForPackageHash($package_hash);
$paths = $map->resolvePackage($package_hash); if (!$resource_names) {
if (!$paths) {
return new Aphront404Response(); return new Aphront404Response();
} }
try { try {
$data = array(); $data = array();
foreach ($paths as $package_path) { foreach ($resource_names as $resource_name) {
$disk_path = $this->getDiskPath($package_path); $data[] = $map->getResourceDataForName($resource_name);
$data[] = Filesystem::readFile($disk_path);
} }
$data = implode("\n\n", $data); $data = implode("\n\n", $data);
} catch (Exception $ex) { } catch (Exception $ex) {
@ -60,8 +56,7 @@ abstract class CelerityResourceController extends PhabricatorController {
} }
} else { } else {
try { try {
$disk_path = $this->getDiskPath($path); $data = $map->getResourceDataForName($path);
$data = Filesystem::readFile($disk_path);
} catch (Exception $ex) { } catch (Exception $ex) {
return new Aphront404Response(); return new Aphront404Response();
} }

View file

@ -90,7 +90,13 @@ final class CelerityResourceMap {
return $packaged; return $packaged;
} }
public function resolvePackage($package_hash) { public function getResourceDataForName($resource_name) {
$root = phutil_get_library_root('phabricator');
$root = dirname($root).'/webroot/';
return Filesystem::readFile($root.$resource_name);
}
public function getResourceNamesForPackageHash($package_hash) {
$package = idx($this->packageMap['packages'], $package_hash); $package = idx($this->packageMap['packages'], $package_hash);
if (!$package) { if (!$package) {
return null; return null;