Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/aphront/response/AphrontProxyResponse.php
12241 views
1
<?php
2
3
/**
4
* Base class for responses which augment other types of responses. For example,
5
* a response might be substantially an Ajax response, but add structure to the
6
* response content. It can do this by extending @{class:AphrontProxyResponse},
7
* instantiating an @{class:AphrontAjaxResponse} in @{method:buildProxy}, and
8
* then constructing a real @{class:AphrontAjaxResponse} in
9
* @{method:reduceProxyResponse}.
10
*/
11
abstract class AphrontProxyResponse
12
extends AphrontResponse
13
implements AphrontResponseProducerInterface {
14
15
private $proxy;
16
17
protected function getProxy() {
18
if (!$this->proxy) {
19
$this->proxy = $this->buildProxy();
20
}
21
return $this->proxy;
22
}
23
24
public function setRequest($request) {
25
$this->getProxy()->setRequest($request);
26
return $this;
27
}
28
29
public function getRequest() {
30
return $this->getProxy()->getRequest();
31
}
32
33
public function getHeaders() {
34
return $this->getProxy()->getHeaders();
35
}
36
37
public function setCacheDurationInSeconds($duration) {
38
$this->getProxy()->setCacheDurationInSeconds($duration);
39
return $this;
40
}
41
42
public function setCanCDN($can_cdn) {
43
$this->getProxy()->setCanCDN($can_cdn);
44
return $this;
45
}
46
47
public function setLastModified($epoch_timestamp) {
48
$this->getProxy()->setLastModified($epoch_timestamp);
49
return $this;
50
}
51
52
public function setHTTPResponseCode($code) {
53
$this->getProxy()->setHTTPResponseCode($code);
54
return $this;
55
}
56
57
public function getHTTPResponseCode() {
58
return $this->getProxy()->getHTTPResponseCode();
59
}
60
61
public function setFrameable($frameable) {
62
$this->getProxy()->setFrameable($frameable);
63
return $this;
64
}
65
66
public function getCacheHeaders() {
67
return $this->getProxy()->getCacheHeaders();
68
}
69
70
abstract protected function buildProxy();
71
abstract public function reduceProxyResponse();
72
73
final public function buildResponseString() {
74
throw new Exception(
75
pht(
76
'%s must implement %s.',
77
__CLASS__,
78
'reduceProxyResponse()'));
79
}
80
81
82
/* -( AphrontResponseProducerInterface )----------------------------------- */
83
84
85
public function produceAphrontResponse() {
86
return $this->reduceProxyResponse();
87
}
88
89
}
90
91