mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-22 23:02:42 +01:00
Store the "current" application in the controller
Summary: When we match an application route, select it as the current application and store it on the controller. Move routes for the major applications into their PhabricatorApplication classes so this works properly. Test Plan: Added a var_dump() and made sure we picked the right app for all these applications. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T1569 Differential Revision: https://secure.phabricator.com/D3144
This commit is contained in:
parent
8240f59fc9
commit
643653dc61
9 changed files with 187 additions and 138 deletions
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Facebook, Inc.
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -22,6 +22,7 @@
|
|||
abstract class AphrontController {
|
||||
|
||||
private $request;
|
||||
private $currentApplication;
|
||||
|
||||
public function willBeginExecution() {
|
||||
return;
|
||||
|
@ -45,4 +46,16 @@ abstract class AphrontController {
|
|||
return $controller->processRequest();
|
||||
}
|
||||
|
||||
|
||||
final public function setCurrentApplication(
|
||||
PhabricatorApplication $current_application) {
|
||||
|
||||
$this->currentApplication = $current_application;
|
||||
return $this;
|
||||
}
|
||||
|
||||
final public function getCurrentApplication() {
|
||||
return $this->currentApplication;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,12 +51,32 @@ abstract class AphrontApplicationConfiguration {
|
|||
}
|
||||
|
||||
final public function buildController() {
|
||||
$map = $this->getURIMap();
|
||||
$mapper = new AphrontURIMapper($map);
|
||||
$request = $this->getRequest();
|
||||
$path = $request->getPath();
|
||||
|
||||
$maps = array();
|
||||
$maps[] = array(null, $this->getURIMap());
|
||||
|
||||
$applications = PhabricatorApplication::getAllInstalledApplications();
|
||||
foreach ($applications as $application) {
|
||||
$maps[] = array($application, $application->getRoutes());
|
||||
}
|
||||
|
||||
$current_application = null;
|
||||
foreach ($maps as $map_info) {
|
||||
list($application, $map) = $map_info;
|
||||
|
||||
$mapper = new AphrontURIMapper($map);
|
||||
list($controller_class, $uri_data) = $mapper->mapPath($path);
|
||||
|
||||
if ($controller_class) {
|
||||
if ($application) {
|
||||
$current_application = $application;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$controller_class) {
|
||||
if (!preg_match('@/$@', $path)) {
|
||||
// If we failed to match anything but don't have a trailing slash, try
|
||||
|
@ -75,6 +95,9 @@ abstract class AphrontApplicationConfiguration {
|
|||
}
|
||||
|
||||
$controller = newv($controller_class, array($request));
|
||||
if ($current_application) {
|
||||
$controller->setCurrentApplication($current_application);
|
||||
}
|
||||
|
||||
return array($controller, $uri_data);
|
||||
}
|
||||
|
|
|
@ -85,32 +85,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
),
|
||||
'/api/(?P<method>[^/]+)' => 'PhabricatorConduitAPIController',
|
||||
|
||||
'/D(?P<id>\d+)' => 'DifferentialRevisionViewController',
|
||||
'/differential/' => array(
|
||||
'' => 'DifferentialRevisionListController',
|
||||
'filter/(?P<filter>\w+)/(?:(?P<username>\w+)/)?' =>
|
||||
'DifferentialRevisionListController',
|
||||
'stats/(?P<filter>\w+)/' => 'DifferentialRevisionStatsController',
|
||||
'diff/' => array(
|
||||
'(?P<id>\d+)/' => 'DifferentialDiffViewController',
|
||||
'create/' => 'DifferentialDiffCreateController',
|
||||
),
|
||||
'changeset/' => 'DifferentialChangesetViewController',
|
||||
'revision/edit/(?:(?P<id>\d+)/)?'
|
||||
=> 'DifferentialRevisionEditController',
|
||||
'comment/' => array(
|
||||
'preview/(?P<id>\d+)/' => 'DifferentialCommentPreviewController',
|
||||
'save/' => 'DifferentialCommentSaveController',
|
||||
'inline/' => array(
|
||||
'preview/(?P<id>\d+)/' =>
|
||||
'DifferentialInlineCommentPreviewController',
|
||||
'edit/(?P<id>\d+)/' => 'DifferentialInlineCommentEditController',
|
||||
),
|
||||
),
|
||||
'subscribe/(?P<action>add|rem)/(?P<id>\d+)/'
|
||||
=> 'DifferentialSubscribeController',
|
||||
),
|
||||
|
||||
'/typeahead/' => array(
|
||||
'common/(?P<type>\w+)/'
|
||||
=> 'PhabricatorTypeaheadCommonDatasourceController',
|
||||
|
@ -182,34 +156,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
'(?:page/(?P<page>[^/]+)/)?' => 'PhabricatorUserSettingsController',
|
||||
),
|
||||
|
||||
'/maniphest/' => array(
|
||||
'' => 'ManiphestTaskListController',
|
||||
'view/(?P<view>\w+)/' => 'ManiphestTaskListController',
|
||||
'report/(?:(?P<view>\w+)/)?' => 'ManiphestReportController',
|
||||
'batch/' => 'ManiphestBatchEditController',
|
||||
'task/' => array(
|
||||
'create/' => 'ManiphestTaskEditController',
|
||||
'edit/(?P<id>\d+)/' => 'ManiphestTaskEditController',
|
||||
'descriptionchange/(?:(?P<id>\d+)/)?' =>
|
||||
'ManiphestTaskDescriptionChangeController',
|
||||
'descriptionpreview/' =>
|
||||
'ManiphestTaskDescriptionPreviewController',
|
||||
),
|
||||
'transaction/' => array(
|
||||
'save/' => 'ManiphestTransactionSaveController',
|
||||
'preview/(?P<id>\d+)/' => 'ManiphestTransactionPreviewController',
|
||||
),
|
||||
'export/(?P<key>[^/]+)/' => 'ManiphestExportController',
|
||||
'subpriority/' => 'ManiphestSubpriorityController',
|
||||
'custom/' => array(
|
||||
'' => 'ManiphestSavedQueryListController',
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'ManiphestSavedQueryEditController',
|
||||
'delete/(?P<id>\d+)/' => 'ManiphestSavedQueryDeleteController',
|
||||
),
|
||||
),
|
||||
|
||||
'/T(?P<id>\d+)' => 'ManiphestTaskDetailController',
|
||||
|
||||
'/repository/' => array(
|
||||
'' => 'PhabricatorRepositoryListController',
|
||||
'create/' => 'PhabricatorRepositoryCreateController',
|
||||
|
@ -241,41 +187,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
=> 'PhabricatorProjectUpdateController',
|
||||
),
|
||||
|
||||
'/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)'
|
||||
=> 'DiffusionCommitController',
|
||||
'/diffusion/' => array(
|
||||
'' => 'DiffusionHomeController',
|
||||
'(?P<callsign>[A-Z]+)/' => array(
|
||||
'' => 'DiffusionRepositoryController',
|
||||
|
||||
'repository/(?P<dblob>.*)' => 'DiffusionRepositoryController',
|
||||
'change/(?P<dblob>.*)' => 'DiffusionChangeController',
|
||||
'history/(?P<dblob>.*)' => 'DiffusionHistoryController',
|
||||
'browse/(?P<dblob>.*)' => 'DiffusionBrowseController',
|
||||
'lastmodified/(?P<dblob>.*)' => 'DiffusionLastModifiedController',
|
||||
'diff/' => 'DiffusionDiffController',
|
||||
'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
|
||||
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
|
||||
|
||||
'commit/(?P<commit>[a-z0-9]+)/branches/'
|
||||
=> 'DiffusionCommitBranchesController',
|
||||
'commit/(?P<commit>[a-z0-9]+)/tags/'
|
||||
=> 'DiffusionCommitTagsController',
|
||||
),
|
||||
'inline/' => array(
|
||||
'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'preview/(?P<phid>[^/]+)/' =>
|
||||
'DiffusionInlineCommentPreviewController',
|
||||
),
|
||||
'services/' => array(
|
||||
'path/' => array(
|
||||
'complete/' => 'DiffusionPathCompleteController',
|
||||
'validate/' => 'DiffusionPathValidateController',
|
||||
),
|
||||
),
|
||||
'symbol/(?P<name>[^/]+)/' => 'DiffusionSymbolController',
|
||||
'external/' => 'DiffusionExternalController',
|
||||
),
|
||||
|
||||
'/daemon/' => array(
|
||||
'task/(?P<id>\d+)/' => 'PhabricatorWorkerTaskDetailController',
|
||||
|
@ -320,14 +231,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
'delete/(?P<id>\d+)/' => 'PhabricatorOwnersDeleteController',
|
||||
),
|
||||
|
||||
'/audit/' => array(
|
||||
'' => 'PhabricatorAuditListController',
|
||||
'view/(?P<filter>[^/]+)/(?:(?P<name>[^/]+)/)?'
|
||||
=> 'PhabricatorAuditListController',
|
||||
'addcomment/' => 'PhabricatorAuditAddCommentController',
|
||||
'preview/(?P<id>\d+)/' => 'PhabricatorAuditPreviewController',
|
||||
),
|
||||
|
||||
'/xhpast/' => array(
|
||||
'' => 'PhabricatorXHPASTViewRunController',
|
||||
'view/(?P<id>\d+)/'
|
||||
|
@ -371,25 +274,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
'create/' => 'PhabricatorSlowvoteCreateController',
|
||||
),
|
||||
|
||||
// Match "/w/" with slug "/".
|
||||
'/w(?P<slug>/)' => 'PhrictionDocumentController',
|
||||
// Match "/w/x/y/z/" with slug "x/y/z/".
|
||||
'/w/(?P<slug>.+/)' => 'PhrictionDocumentController',
|
||||
|
||||
'/phriction/' => array(
|
||||
'' => 'PhrictionListController',
|
||||
'list/(?P<view>[^/]+)/' => 'PhrictionListController',
|
||||
|
||||
'history(?P<slug>/)' => 'PhrictionHistoryController',
|
||||
'history/(?P<slug>.+/)' => 'PhrictionHistoryController',
|
||||
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'PhrictionEditController',
|
||||
'delete/(?P<id>\d+)/' => 'PhrictionDeleteController',
|
||||
|
||||
'preview/' => 'PhrictionDocumentPreviewController',
|
||||
'diff/(?P<id>\d+)/' => 'PhrictionDiffController',
|
||||
),
|
||||
|
||||
'/phame/' => array(
|
||||
'' => 'PhameAllPostListController',
|
||||
'post/' => array(
|
||||
|
@ -453,13 +337,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
'clear/' => 'PhabricatorNotificationClearController',
|
||||
),
|
||||
|
||||
'/flag/' => array(
|
||||
'' => 'PhabricatorFlagListController',
|
||||
'view/(?P<view>[^/]+)/' => 'PhabricatorFlagListController',
|
||||
'edit/(?P<phid>[^/]+)/' => 'PhabricatorFlagEditController',
|
||||
'delete/(?P<id>\d+)/' => 'PhabricatorFlagDeleteController',
|
||||
),
|
||||
|
||||
'/phortune/' => array(
|
||||
'stripe/' => array(
|
||||
'testpaymentform/' => 'PhortuneStripeTestPaymentFormController',
|
||||
|
@ -469,7 +346,7 @@ class AphrontDefaultApplicationConfiguration
|
|||
'/emailverify/(?P<code>[^/]+)/' =>
|
||||
'PhabricatorEmailVerificationController',
|
||||
|
||||
) + $this->getApplicationRoutes();
|
||||
);
|
||||
}
|
||||
|
||||
protected function getResourceURIMapRules() {
|
||||
|
@ -483,15 +360,6 @@ class AphrontDefaultApplicationConfiguration
|
|||
);
|
||||
}
|
||||
|
||||
private function getApplicationRoutes() {
|
||||
$applications = PhabricatorApplication::getAllInstalledApplications();
|
||||
$routes = array();
|
||||
foreach ($applications as $application) {
|
||||
$routes += $application->getRoutes();
|
||||
}
|
||||
return $routes;
|
||||
}
|
||||
|
||||
public function buildRequest() {
|
||||
$request = new AphrontRequest($this->getHost(), $this->getPath());
|
||||
$request->setRequestData($_GET + $_POST);
|
||||
|
|
|
@ -26,11 +26,22 @@ final class PhabricatorApplicationAudit extends PhabricatorApplication {
|
|||
return '/audit/';
|
||||
}
|
||||
|
||||
|
||||
public function getIconURI() {
|
||||
return celerity_get_resource_uri('/rsrc/image/app/app_audit.png');
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/audit/' => array(
|
||||
'' => 'PhabricatorAuditListController',
|
||||
'view/(?P<filter>[^/]+)/(?:(?P<name>[^/]+)/)?'
|
||||
=> 'PhabricatorAuditListController',
|
||||
'addcomment/' => 'PhabricatorAuditAddCommentController',
|
||||
'preview/(?P<id>\d+)/' => 'PhabricatorAuditPreviewController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function loadStatus(PhabricatorUser $user) {
|
||||
$status = array();
|
||||
|
||||
|
|
|
@ -36,6 +36,36 @@ final class PhabricatorApplicationDifferential extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/D(?P<id>\d+)' => 'DifferentialRevisionViewController',
|
||||
'/differential/' => array(
|
||||
'' => 'DifferentialRevisionListController',
|
||||
'filter/(?P<filter>\w+)/(?:(?P<username>\w+)/)?' =>
|
||||
'DifferentialRevisionListController',
|
||||
'stats/(?P<filter>\w+)/' => 'DifferentialRevisionStatsController',
|
||||
'diff/' => array(
|
||||
'(?P<id>\d+)/' => 'DifferentialDiffViewController',
|
||||
'create/' => 'DifferentialDiffCreateController',
|
||||
),
|
||||
'changeset/' => 'DifferentialChangesetViewController',
|
||||
'revision/edit/(?:(?P<id>\d+)/)?'
|
||||
=> 'DifferentialRevisionEditController',
|
||||
'comment/' => array(
|
||||
'preview/(?P<id>\d+)/' => 'DifferentialCommentPreviewController',
|
||||
'save/' => 'DifferentialCommentSaveController',
|
||||
'inline/' => array(
|
||||
'preview/(?P<id>\d+)/' =>
|
||||
'DifferentialInlineCommentPreviewController',
|
||||
'edit/(?P<id>\d+)/' => 'DifferentialInlineCommentEditController',
|
||||
),
|
||||
),
|
||||
'subscribe/(?P<action>add|rem)/(?P<id>\d+)/'
|
||||
=> 'DifferentialSubscribeController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function loadStatus(PhabricatorUser $user) {
|
||||
$revisions = id(new DifferentialRevisionQuery())
|
||||
->withResponsibleUsers(array($user->getPHID()))
|
||||
|
|
|
@ -30,5 +30,45 @@ final class PhabricatorApplicationDiffusion extends PhabricatorApplication {
|
|||
return celerity_get_resource_uri('/rsrc/image/app/app_diffusion.png');
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/r(?P<callsign>[A-Z]+)(?P<commit>[a-z0-9]+)'
|
||||
=> 'DiffusionCommitController',
|
||||
'/diffusion/' => array(
|
||||
'' => 'DiffusionHomeController',
|
||||
'(?P<callsign>[A-Z]+)/' => array(
|
||||
'' => 'DiffusionRepositoryController',
|
||||
|
||||
'repository/(?P<dblob>.*)' => 'DiffusionRepositoryController',
|
||||
'change/(?P<dblob>.*)' => 'DiffusionChangeController',
|
||||
'history/(?P<dblob>.*)' => 'DiffusionHistoryController',
|
||||
'browse/(?P<dblob>.*)' => 'DiffusionBrowseController',
|
||||
'lastmodified/(?P<dblob>.*)' => 'DiffusionLastModifiedController',
|
||||
'diff/' => 'DiffusionDiffController',
|
||||
'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
|
||||
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
|
||||
|
||||
'commit/(?P<commit>[a-z0-9]+)/branches/'
|
||||
=> 'DiffusionCommitBranchesController',
|
||||
'commit/(?P<commit>[a-z0-9]+)/tags/'
|
||||
=> 'DiffusionCommitTagsController',
|
||||
),
|
||||
'inline/' => array(
|
||||
'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'preview/(?P<phid>[^/]+)/' =>
|
||||
'DiffusionInlineCommentPreviewController',
|
||||
),
|
||||
'services/' => array(
|
||||
'path/' => array(
|
||||
'complete/' => 'DiffusionPathCompleteController',
|
||||
'validate/' => 'DiffusionPathValidateController',
|
||||
),
|
||||
),
|
||||
'symbol/(?P<name>[^/]+)/' => 'DiffusionSymbolController',
|
||||
'external/' => 'DiffusionExternalController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -49,5 +49,16 @@ final class PhabricatorApplicationFlags extends PhabricatorApplication {
|
|||
return $status;
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/flag/' => array(
|
||||
'' => 'PhabricatorFlagListController',
|
||||
'view/(?P<view>[^/]+)/' => 'PhabricatorFlagListController',
|
||||
'edit/(?P<phid>[^/]+)/' => 'PhabricatorFlagEditController',
|
||||
'delete/(?P<id>\d+)/' => 'PhabricatorFlagDeleteController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,37 @@ final class PhabricatorApplicationManiphest extends PhabricatorApplication {
|
|||
);
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
'/T(?P<id>\d+)' => 'ManiphestTaskDetailController',
|
||||
'/maniphest/' => array(
|
||||
'' => 'ManiphestTaskListController',
|
||||
'view/(?P<view>\w+)/' => 'ManiphestTaskListController',
|
||||
'report/(?:(?P<view>\w+)/)?' => 'ManiphestReportController',
|
||||
'batch/' => 'ManiphestBatchEditController',
|
||||
'task/' => array(
|
||||
'create/' => 'ManiphestTaskEditController',
|
||||
'edit/(?P<id>\d+)/' => 'ManiphestTaskEditController',
|
||||
'descriptionchange/(?:(?P<id>\d+)/)?' =>
|
||||
'ManiphestTaskDescriptionChangeController',
|
||||
'descriptionpreview/' =>
|
||||
'ManiphestTaskDescriptionPreviewController',
|
||||
),
|
||||
'transaction/' => array(
|
||||
'save/' => 'ManiphestTransactionSaveController',
|
||||
'preview/(?P<id>\d+)/' => 'ManiphestTransactionPreviewController',
|
||||
),
|
||||
'export/(?P<key>[^/]+)/' => 'ManiphestExportController',
|
||||
'subpriority/' => 'ManiphestSubpriorityController',
|
||||
'custom/' => array(
|
||||
'' => 'ManiphestSavedQueryListController',
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'ManiphestSavedQueryEditController',
|
||||
'delete/(?P<id>\d+)/' => 'ManiphestSavedQueryDeleteController',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function loadStatus(PhabricatorUser $user) {
|
||||
$status = array();
|
||||
|
||||
|
|
|
@ -30,6 +30,28 @@ final class PhabricatorApplicationPhriction extends PhabricatorApplication {
|
|||
return celerity_get_resource_uri('/rsrc/image/app/app_phriction.png');
|
||||
}
|
||||
|
||||
public function getRoutes() {
|
||||
return array(
|
||||
// Match "/w/" with slug "/".
|
||||
'/w(?P<slug>/)' => 'PhrictionDocumentController',
|
||||
// Match "/w/x/y/z/" with slug "x/y/z/".
|
||||
'/w/(?P<slug>.+/)' => 'PhrictionDocumentController',
|
||||
|
||||
'/phriction/' => array(
|
||||
'' => 'PhrictionListController',
|
||||
'list/(?P<view>[^/]+)/' => 'PhrictionListController',
|
||||
|
||||
'history(?P<slug>/)' => 'PhrictionHistoryController',
|
||||
'history/(?P<slug>.+/)' => 'PhrictionHistoryController',
|
||||
|
||||
'edit/(?:(?P<id>\d+)/)?' => 'PhrictionEditController',
|
||||
'delete/(?P<id>\d+)/' => 'PhrictionDeleteController',
|
||||
|
||||
'preview/' => 'PhrictionDocumentPreviewController',
|
||||
'diff/(?P<id>\d+)/' => 'PhrictionDiffController',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue