@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3abstract 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 handleRequest(AphrontRequest $request) {
28 if (method_exists($this, 'processRequest')) {
29 return $this->processRequest();
30 }
31
32 throw new PhutilMethodNotImplementedException(
33 pht(
34 'Controllers must implement either %s (recommended) '.
35 'or %s (deprecated).',
36 'handleRequest()',
37 'processRequest()'));
38 }
39
40 public function willSendResponse(AphrontResponse $response) {
41 return $response;
42 }
43
44 final public function setRequest(AphrontRequest $request) {
45 $this->request = $request;
46 return $this;
47 }
48
49 final public function getRequest() {
50 if (!$this->request) {
51 throw new PhutilInvalidStateException('setRequest');
52 }
53 return $this->request;
54 }
55
56 final public function getViewer() {
57 return $this->getRequest()->getViewer();
58 }
59
60 final public function delegateToController(AphrontController $controller) {
61 $request = $this->getRequest();
62
63 $controller->setDelegatingController($this);
64 $controller->setRequest($request);
65
66 $application = $this->getCurrentApplication();
67 if ($application) {
68 $controller->setCurrentApplication($application);
69 }
70
71 return $controller->handleRequest($request);
72 }
73
74 final public function setCurrentApplication(
75 PhabricatorApplication $current_application) {
76
77 $this->currentApplication = $current_application;
78 return $this;
79 }
80
81 final public function getCurrentApplication() {
82 return $this->currentApplication;
83 }
84
85 public function getDefaultResourceSource() {
86 throw new PhutilMethodNotImplementedException(
87 pht(
88 'A Controller must implement %s before you can invoke %s or %s.',
89 'getDefaultResourceSource()',
90 'requireResource()',
91 'initBehavior()'));
92 }
93
94 public function requireResource($symbol) {
95 $response = CelerityAPI::getStaticResourceResponse();
96 $response->requireResource($symbol, $this->getDefaultResourceSource());
97 return $this;
98 }
99
100 public function initBehavior($name, $config = array()) {
101 Javelin::initBehavior(
102 $name,
103 $config,
104 $this->getDefaultResourceSource());
105 }
106
107}