mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Serve celerity resources from multiple maps
Summary: Ref T4222. Adds the map name to Celerity resource URIs, so we can serve out of any map. Test Plan: Poked around, verified URIs have "/phabricator/" in them now. Reviewers: btrahan, hach-que Reviewed By: btrahan CC: aran Maniphest Tasks: T4222 Differential Revision: https://secure.phabricator.com/D7877
This commit is contained in:
parent
31b6f69ff7
commit
5ce0edaf69
4 changed files with 23 additions and 2 deletions
|
@ -73,6 +73,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
return array(
|
||||
'/res/' => array(
|
||||
'(?:(?P<mtime>[0-9]+)T/)?'.
|
||||
'(?P<library>[^/]+)/'.
|
||||
'(?P<hash>[a-f0-9]{8})/'.
|
||||
'(?P<path>.+\.(?:css|js|jpg|png|swf|gif))'
|
||||
=> 'CelerityPhabricatorResourceController',
|
||||
|
|
|
@ -12,17 +12,27 @@ final class CelerityPhabricatorResourceController
|
|||
|
||||
private $path;
|
||||
private $hash;
|
||||
private $library;
|
||||
|
||||
public function getCelerityResourceMap() {
|
||||
return CelerityResourceMap::getNamedInstance('phabricator');
|
||||
return CelerityResourceMap::getNamedInstance($this->library);
|
||||
}
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->path = $data['path'];
|
||||
$this->hash = $data['hash'];
|
||||
$this->library = $data['library'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
// Check that the resource library exists before trying to serve resources
|
||||
// from it.
|
||||
try {
|
||||
$this->getCelerityResourceMap();
|
||||
} catch (Exception $ex) {
|
||||
return new Aphront400Response();
|
||||
}
|
||||
|
||||
return $this->serveResource($this->path);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,15 @@ abstract class CelerityPhysicalResources extends CelerityResources {
|
|||
|
||||
foreach ($resources_list as $resources) {
|
||||
$name = $resources->getName();
|
||||
|
||||
if (!preg_match('/^[a-z0-9]+/', $name)) {
|
||||
throw new Exception(
|
||||
pht(
|
||||
'Resources name "%s" is not valid; it must contain only '.
|
||||
'lowercase latin letters and digits.',
|
||||
$name));
|
||||
}
|
||||
|
||||
if (empty($resources_map[$name])) {
|
||||
$resources_map[$name] = $resources;
|
||||
} else {
|
||||
|
|
|
@ -25,7 +25,8 @@ abstract class CelerityResources {
|
|||
}
|
||||
|
||||
public function getResourceURI($hash, $name) {
|
||||
return "/res/{$hash}/{$name}";
|
||||
$resources = $this->getName();
|
||||
return "/res/{$resources}/{$hash}/{$name}";
|
||||
}
|
||||
|
||||
public function getResourcePackages() {
|
||||
|
|
Loading…
Reference in a new issue