mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-03 11:21:01 +01:00
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
This commit is contained in:
parent
4fe09a0ac7
commit
dd669c6d4e
4 changed files with 29 additions and 9 deletions
|
@ -5,8 +5,8 @@
|
||||||
* a response might be substantially an Ajax response, but add structure to the
|
* a response might be substantially an Ajax response, but add structure to the
|
||||||
* response content. It can do this by extending @{class:AphrontProxyResponse},
|
* response content. It can do this by extending @{class:AphrontProxyResponse},
|
||||||
* instantiating an @{class:AphrontAjaxResponse} in @{method:buildProxy}, and
|
* instantiating an @{class:AphrontAjaxResponse} in @{method:buildProxy}, and
|
||||||
* then using the proxy to construct the response string in
|
* then constructing a real @{class:AphrontAjaxResponse} in
|
||||||
* @{method:buildResponseString}.
|
* @{method:reduceProxyResponse}.
|
||||||
*
|
*
|
||||||
* @group aphront
|
* @group aphront
|
||||||
*/
|
*/
|
||||||
|
@ -63,5 +63,12 @@ abstract class AphrontProxyResponse extends AphrontResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected function buildProxy();
|
abstract protected function buildProxy();
|
||||||
|
abstract public function reduceProxyResponse();
|
||||||
|
|
||||||
|
final public function buildResponseString() {
|
||||||
|
throw new Exception(
|
||||||
|
"AphrontProxyResponse must implement reduceProxyResponse().");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,6 +181,22 @@ abstract class PhabricatorController extends AphrontController {
|
||||||
public function didProcessRequest($response) {
|
public function didProcessRequest($response) {
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
$response->setRequest($request);
|
$response->setRequest($request);
|
||||||
|
|
||||||
|
$seen = array();
|
||||||
|
while ($response instanceof AphrontProxyResponse) {
|
||||||
|
|
||||||
|
$hash = spl_object_hash($response);
|
||||||
|
if (isset($seen[$hash])) {
|
||||||
|
$seen[] = get_class($response);
|
||||||
|
throw new Exception(
|
||||||
|
"Cycle while reducing proxy responses: ".
|
||||||
|
implode(' -> ', $seen));
|
||||||
|
}
|
||||||
|
$seen[$hash] = get_class($response);
|
||||||
|
|
||||||
|
$response = $response->reduceProxyResponse();
|
||||||
|
}
|
||||||
|
|
||||||
if ($response instanceof AphrontDialogResponse) {
|
if ($response instanceof AphrontDialogResponse) {
|
||||||
if (!$request->isAjax()) {
|
if (!$request->isAjax()) {
|
||||||
$view = new PhabricatorStandardPageView();
|
$view = new PhabricatorStandardPageView();
|
||||||
|
|
|
@ -40,7 +40,7 @@ final class PhabricatorApplicationTransactionResponse
|
||||||
return $this->viewer;
|
return $this->viewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildResponseString() {
|
public function reduceProxyResponse() {
|
||||||
$view = id(new PhabricatorApplicationTransactionView())
|
$view = id(new PhabricatorApplicationTransactionView())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->setTransactions($this->getTransactions());
|
->setTransactions($this->getTransactions());
|
||||||
|
@ -56,10 +56,7 @@ final class PhabricatorApplicationTransactionResponse
|
||||||
'spacer' => PhabricatorTimelineView::renderSpacer(),
|
'spacer' => PhabricatorTimelineView::renderSpacer(),
|
||||||
);
|
);
|
||||||
|
|
||||||
return $this
|
return $this->getProxy()->setContent($content);
|
||||||
->getProxy()
|
|
||||||
->setContent($content)
|
|
||||||
->buildResponseString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ final class PhabricatorChangesetResponse extends AphrontProxyResponse {
|
||||||
return new AphrontAjaxResponse();
|
return new AphrontAjaxResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildResponseString() {
|
public function reduceProxyResponse() {
|
||||||
$content = array(
|
$content = array(
|
||||||
'changeset' => $this->renderedChangeset,
|
'changeset' => $this->renderedChangeset,
|
||||||
);
|
);
|
||||||
|
@ -28,7 +28,7 @@ final class PhabricatorChangesetResponse extends AphrontProxyResponse {
|
||||||
$content['coverage'] = $this->coverage;
|
$content['coverage'] = $this->coverage;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->getProxy()->setContent($content)->buildResponseString();
|
return $this->getProxy()->setContent($content);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue