1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 02:32: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:
epriestley 2014-01-02 11:59:45 -08:00
parent 31b6f69ff7
commit 5ce0edaf69
4 changed files with 23 additions and 2 deletions

View file

@ -73,6 +73,7 @@ class AphrontDefaultApplicationConfiguration
return array( return array(
'/res/' => array( '/res/' => array(
'(?:(?P<mtime>[0-9]+)T/)?'. '(?:(?P<mtime>[0-9]+)T/)?'.
'(?P<library>[^/]+)/'.
'(?P<hash>[a-f0-9]{8})/'. '(?P<hash>[a-f0-9]{8})/'.
'(?P<path>.+\.(?:css|js|jpg|png|swf|gif))' '(?P<path>.+\.(?:css|js|jpg|png|swf|gif))'
=> 'CelerityPhabricatorResourceController', => 'CelerityPhabricatorResourceController',

View file

@ -12,17 +12,27 @@ final class CelerityPhabricatorResourceController
private $path; private $path;
private $hash; private $hash;
private $library;
public function getCelerityResourceMap() { public function getCelerityResourceMap() {
return CelerityResourceMap::getNamedInstance('phabricator'); return CelerityResourceMap::getNamedInstance($this->library);
} }
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->path = $data['path']; $this->path = $data['path'];
$this->hash = $data['hash']; $this->hash = $data['hash'];
$this->library = $data['library'];
} }
public function processRequest() { 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); return $this->serveResource($this->path);
} }

View file

@ -30,6 +30,15 @@ abstract class CelerityPhysicalResources extends CelerityResources {
foreach ($resources_list as $resources) { foreach ($resources_list as $resources) {
$name = $resources->getName(); $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])) { if (empty($resources_map[$name])) {
$resources_map[$name] = $resources; $resources_map[$name] = $resources;
} else { } else {

View file

@ -25,7 +25,8 @@ abstract class CelerityResources {
} }
public function getResourceURI($hash, $name) { public function getResourceURI($hash, $name) {
return "/res/{$hash}/{$name}"; $resources = $this->getName();
return "/res/{$resources}/{$hash}/{$name}";
} }
public function getResourcePackages() { public function getResourcePackages() {