mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-24 07:42:40 +01:00
31b6f69ff7
Summary: Ref T4222. Currently, CelerityResourceResponse holds response resources in flat maps. Instead, specify which map resources appear in. Also, provide `requireResource()` and `initBehavior()` APIs on the Controller and View base classes. These provide a cleaner abstraction over `require_celerity_resource()` and `Javelin::initBehavior()`, but are otherwise the same. Move a few callsites over. Test Plan: - Reloaded pages. - Browsed around Differential. Reviewers: btrahan, hach-que Reviewed By: btrahan CC: aran Maniphest Tasks: T4222 Differential Revision: https://secure.phabricator.com/D7876
86 lines
2 KiB
PHP
86 lines
2 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group aphront
|
|
*/
|
|
abstract class AphrontController extends Phobject {
|
|
|
|
private $request;
|
|
private $currentApplication;
|
|
private $delegatingController;
|
|
|
|
public function setDelegatingController(
|
|
AphrontController $delegating_controller) {
|
|
$this->delegatingController = $delegating_controller;
|
|
return $this;
|
|
}
|
|
|
|
public function getDelegatingController() {
|
|
return $this->delegatingController;
|
|
}
|
|
|
|
public function willBeginExecution() {
|
|
return;
|
|
}
|
|
|
|
public function willProcessRequest(array $uri_data) {
|
|
return;
|
|
}
|
|
|
|
public function didProcessRequest($response) {
|
|
return $response;
|
|
}
|
|
|
|
abstract public function processRequest();
|
|
|
|
final public function __construct(AphrontRequest $request) {
|
|
$this->request = $request;
|
|
}
|
|
|
|
final public function getRequest() {
|
|
return $this->request;
|
|
}
|
|
|
|
final public function delegateToController(AphrontController $controller) {
|
|
$controller->setDelegatingController($this);
|
|
|
|
$application = $this->getCurrentApplication();
|
|
if ($application) {
|
|
$controller->setCurrentApplication($application);
|
|
}
|
|
|
|
return $controller->processRequest();
|
|
}
|
|
|
|
final public function setCurrentApplication(
|
|
PhabricatorApplication $current_application) {
|
|
|
|
$this->currentApplication = $current_application;
|
|
return $this;
|
|
}
|
|
|
|
final public function getCurrentApplication() {
|
|
return $this->currentApplication;
|
|
}
|
|
|
|
public function getDefaultResourceSource() {
|
|
throw new Exception(
|
|
pht(
|
|
'A Controller must implement getDefaultResourceSource() before you '.
|
|
'can invoke requireResource() or initBehavior().'));
|
|
}
|
|
|
|
public function requireResource($symbol) {
|
|
$response = CelerityAPI::getStaticResourceResponse();
|
|
$response->requireResource($symbol, $this->getDefaultResourceSource());
|
|
return $this;
|
|
}
|
|
|
|
public function initBehavior($name, $config = array()) {
|
|
Javelin::initBehavior(
|
|
$name,
|
|
$config,
|
|
$this->getDefaultResourceSource());
|
|
}
|
|
|
|
}
|