Skip to content

Commit dd669c6

Browse files
author
epriestley
committed
Make AphrontProxyResponse reduce to a real response instead of building a string
Summary: Currently, AphrontProxyResponse is expected to build a string. This prevents some response types (like Dialog) from being proxied, because they have special rules. Instead, make proxy responses reduce into a non-proxied response so it's possible to proxy any type of response and hit all the normal rules for it. Test Plan: Built a proxied DialogResponse on top of this. Reviewers: btrahan, vrana Reviewed By: btrahan CC: aran Maniphest Tasks: T2104, T912 Differential Revision: https://secure.phabricator.com/D4159
1 parent 4fe09a0 commit dd669c6

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

src/aphront/response/AphrontProxyResponse.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* a response might be substantially an Ajax response, but add structure to the
66
* response content. It can do this by extending @{class:AphrontProxyResponse},
77
* instantiating an @{class:AphrontAjaxResponse} in @{method:buildProxy}, and
8-
* then using the proxy to construct the response string in
9-
* @{method:buildResponseString}.
8+
* then constructing a real @{class:AphrontAjaxResponse} in
9+
* @{method:reduceProxyResponse}.
1010
*
1111
* @group aphront
1212
*/
@@ -63,5 +63,12 @@ public function getCacheHeaders() {
6363
}
6464

6565
abstract protected function buildProxy();
66+
abstract public function reduceProxyResponse();
67+
68+
final public function buildResponseString() {
69+
throw new Exception(
70+
"AphrontProxyResponse must implement reduceProxyResponse().");
71+
}
72+
6673

6774
}

src/applications/base/controller/PhabricatorController.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,22 @@ public function buildApplicationPage($view, array $options) {
181181
public function didProcessRequest($response) {
182182
$request = $this->getRequest();
183183
$response->setRequest($request);
184+
185+
$seen = array();
186+
while ($response instanceof AphrontProxyResponse) {
187+
188+
$hash = spl_object_hash($response);
189+
if (isset($seen[$hash])) {
190+
$seen[] = get_class($response);
191+
throw new Exception(
192+
"Cycle while reducing proxy responses: ".
193+
implode(' -> ', $seen));
194+
}
195+
$seen[$hash] = get_class($response);
196+
197+
$response = $response->reduceProxyResponse();
198+
}
199+
184200
if ($response instanceof AphrontDialogResponse) {
185201
if (!$request->isAjax()) {
186202
$view = new PhabricatorStandardPageView();

src/applications/transactions/response/PhabricatorApplicationTransactionResponse.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getViewer() {
4040
return $this->viewer;
4141
}
4242

43-
public function buildResponseString() {
43+
public function reduceProxyResponse() {
4444
$view = id(new PhabricatorApplicationTransactionView())
4545
->setViewer($this->getViewer())
4646
->setTransactions($this->getTransactions());
@@ -56,10 +56,7 @@ public function buildResponseString() {
5656
'spacer' => PhabricatorTimelineView::renderSpacer(),
5757
);
5858

59-
return $this
60-
->getProxy()
61-
->setContent($content)
62-
->buildResponseString();
59+
return $this->getProxy()->setContent($content);
6360
}
6461

6562
}

src/infrastructure/diff/PhabricatorChangesetResponse.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function buildProxy() {
1919
return new AphrontAjaxResponse();
2020
}
2121

22-
public function buildResponseString() {
22+
public function reduceProxyResponse() {
2323
$content = array(
2424
'changeset' => $this->renderedChangeset,
2525
);
@@ -28,7 +28,7 @@ public function buildResponseString() {
2828
$content['coverage'] = $this->coverage;
2929
}
3030

31-
return $this->getProxy()->setContent($content)->buildResponseString();
31+
return $this->getProxy()->setContent($content);
3232
}
3333

3434
}

0 commit comments

Comments
 (0)