Index: src/applications/phame/controller/PhameResourceController.php =================================================================== --- src/applications/phame/controller/PhameResourceController.php +++ src/applications/phame/controller/PhameResourceController.php @@ -10,7 +10,7 @@ private $name; private $root; - protected function getRootDirectory() { + protected function getRootDirectory($module) { return $this->root; } Index: src/infrastructure/celerity/CelerityPhabricatorResourceController.php =================================================================== --- src/infrastructure/celerity/CelerityPhabricatorResourceController.php +++ src/infrastructure/celerity/CelerityPhabricatorResourceController.php @@ -14,8 +14,8 @@ private $hash; private $package; - protected function getRootDirectory() { - $root = dirname(phutil_get_library_root('phabricator')); + protected function getRootDirectory($module) { + $root = dirname(phutil_get_library_root($module)); return $root.'/webroot/'; } Index: src/infrastructure/celerity/CelerityResourceController.php =================================================================== --- src/infrastructure/celerity/CelerityResourceController.php +++ src/infrastructure/celerity/CelerityResourceController.php @@ -2,7 +2,7 @@ abstract class CelerityResourceController extends PhabricatorController { - abstract protected function getRootDirectory(); + abstract protected function getRootDirectory($module); protected function buildResourceTransformer() { return null; @@ -16,8 +16,8 @@ return false; } - private function getDiskPath($to_resource = null) { - return $this->getRootDirectory().$to_resource; + private function getDiskPath($module, $to_resource = null) { + return $this->getRootDirectory($module).$to_resource; } protected function serveResource($path, $package_hash = null) { @@ -44,6 +44,7 @@ if ($package_hash) { $map = CelerityResourceMap::getInstance(); $paths = $map->resolvePackage($package_hash); + $module = $map->resolvePackageModule($package_hash); if (!$paths) { return new Aphront404Response(); } @@ -51,7 +52,7 @@ try { $data = array(); foreach ($paths as $package_path) { - $disk_path = $this->getDiskPath($package_path); + $disk_path = $this->getDiskPath($module, $package_path); $data[] = Filesystem::readFile($disk_path); } $data = implode("\n\n", $data); @@ -59,8 +60,13 @@ return new Aphront404Response(); } } else { + $map = CelerityResourceMap::getInstance(); + $info = $map->lookupFileInformation('/'.$path); + if ($info === null) { + return new Aphront404Response(); + } try { - $disk_path = $this->getDiskPath($path); + $disk_path = $this->getDiskPath($info['module'], $info['disk']); $data = Filesystem::readFile($disk_path); } catch (Exception $ex) { return new Aphront404Response(); Index: src/infrastructure/celerity/CelerityResourceMap.php =================================================================== --- src/infrastructure/celerity/CelerityResourceMap.php +++ src/infrastructure/celerity/CelerityResourceMap.php @@ -18,21 +18,45 @@ public static function getInstance() { if (empty(self::$instance)) { self::$instance = new CelerityResourceMap(); - $root = phutil_get_library_root('phabricator'); - - $path = PhabricatorEnv::getEnvConfig('celerity.resource-path'); - $ok = include_once $root.'/'.$path; - if (!$ok) { - throw new Exception( - "Failed to load Celerity resource map! Check the ". - "'celerity.resource-path' setting in your configuration."); + + $bootloader = PhutilBootloader::getInstance(); + + foreach ($bootloader->getAllLibraries() as $name) { + if ($name === 'phabricator') { + $path = PhabricatorEnv::getEnvConfig('celerity.resource-path'); + } else { + $path = '/../src/__celerity_resource_map__.php'; + } + + $root = phutil_get_library_root($name); + if ($name === 'phabricator' || file_exists($root.'/'.$path)) { + $ok = include_once $root.'/'.$path; + if (!$ok) { + if ($name === 'phabricator') { + throw new Exception( + "Failed to load Celerity resource map! Check the ". + "'celerity.resource-path' setting in your configuration."); + } else { + throw new Exception( + "Failed to load Celerity resource map for '$name'."); + } + } + } } } return self::$instance; } - public function setResourceMap($resource_map) { - $this->resourceMap = $resource_map; + public function addResourceMap($resource_map) { + if ($this->resourceMap === null) { + $this->resourceMap = $resource_map; + return $this; + } + + // We need to add to the resource map instead. + foreach ($resource_map as $key => $value) { + $this->resourceMap[$key] = $value; + } return $this; } @@ -65,8 +89,19 @@ $map[$symbol] = $info; } - public function setPackageMap($package_map) { - $this->packageMap = $package_map; + public function addPackageMap($package_map) { + if ($this->packageMap === null) { + $this->packageMap = $package_map; + return $this; + } + + // We need to add to the package map instead. + foreach ($package_map["packages"] as $key => $value) { + $this->packageMap["packages"][$key] = $value; + } + foreach ($package_map["reverse"] as $key => $value) { + $this->packageMap["reverse"][$key] = $value; + } return $this; } @@ -105,6 +140,15 @@ return $paths; } + public function resolvePackageModule($package_hash) { + $package = idx($this->packageMap['packages'], $package_hash); + if (!$package) { + return null; + } + + return $package['module']; + } + public function lookupSymbolInformation($symbol) { return idx($this->resourceMap, $symbol); } Index: src/infrastructure/celerity/map.php =================================================================== --- src/infrastructure/celerity/map.php +++ src/infrastructure/celerity/map.php @@ -8,6 +8,6 @@ */ function celerity_register_resource_map(array $map, array $package_map) { $instance = CelerityResourceMap::getInstance(); - $instance->setResourceMap($map); - $instance->setPackageMap($package_map); + $instance->addResourceMap($map); + $instance->addPackageMap($package_map); }