[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class AphrontController extends Phobject { 4 5 private $request; 6 private $currentApplication; 7 private $delegatingController; 8 9 public function setDelegatingController( 10 AphrontController $delegating_controller) { 11 $this->delegatingController = $delegating_controller; 12 return $this; 13 } 14 15 public function getDelegatingController() { 16 return $this->delegatingController; 17 } 18 19 public function willBeginExecution() { 20 return; 21 } 22 23 public function willProcessRequest(array $uri_data) { 24 return; 25 } 26 27 public function didProcessRequest($response) { 28 return $response; 29 } 30 31 public function handleRequest(AphrontRequest $request) { 32 if (method_exists($this, 'processRequest')) { 33 return $this->processRequest(); 34 } 35 36 throw new PhutilMethodNotImplementedException( 37 pht( 38 'Controllers must implement either handleRequest() (recommended) '. 39 'or processRequest() (deprecated).')); 40 } 41 42 final public function setRequest(AphrontRequest $request) { 43 $this->request = $request; 44 return $this; 45 } 46 47 final public function getRequest() { 48 if (!$this->request) { 49 throw new Exception(pht('Call setRequest() before getRequest()!')); 50 } 51 return $this->request; 52 } 53 54 final public function getViewer() { 55 return $this->getRequest()->getViewer(); 56 } 57 58 final public function delegateToController(AphrontController $controller) { 59 $request = $this->getRequest(); 60 61 $controller->setDelegatingController($this); 62 $controller->setRequest($request); 63 64 $application = $this->getCurrentApplication(); 65 if ($application) { 66 $controller->setCurrentApplication($application); 67 } 68 69 return $controller->handleRequest($request); 70 } 71 72 final public function setCurrentApplication( 73 PhabricatorApplication $current_application) { 74 75 $this->currentApplication = $current_application; 76 return $this; 77 } 78 79 final public function getCurrentApplication() { 80 return $this->currentApplication; 81 } 82 83 public function getDefaultResourceSource() { 84 throw new Exception( 85 pht( 86 'A Controller must implement getDefaultResourceSource() before you '. 87 'can invoke requireResource() or initBehavior().')); 88 } 89 90 public function requireResource($symbol) { 91 $response = CelerityAPI::getStaticResourceResponse(); 92 $response->requireResource($symbol, $this->getDefaultResourceSource()); 93 return $this; 94 } 95 96 public function initBehavior($name, $config = array()) { 97 Javelin::initBehavior( 98 $name, 99 $config, 100 $this->getDefaultResourceSource()); 101 } 102 103 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |