Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/aphront/response/AphrontAjaxResponse.php
12241 views
1
<?php
2
3
final class AphrontAjaxResponse extends AphrontResponse {
4
5
private $content;
6
private $error;
7
private $disableConsole;
8
9
public function setContent($content) {
10
$this->content = $content;
11
return $this;
12
}
13
14
public function setError($error) {
15
$this->error = $error;
16
return $this;
17
}
18
19
public function setDisableConsole($disable) {
20
$this->disableConsole = $disable;
21
return $this;
22
}
23
24
private function getConsole() {
25
if ($this->disableConsole) {
26
$console = null;
27
} else {
28
$request = $this->getRequest();
29
$console = $request->getApplicationConfiguration()->getConsole();
30
}
31
return $console;
32
}
33
34
public function buildResponseString() {
35
$request = $this->getRequest();
36
$console = $this->getConsole();
37
if ($console) {
38
// NOTE: We're stripping query parameters here both for readability and
39
// to mitigate BREACH and similar attacks. The parameters are available
40
// in the "Request" tab, so this should not impact usability. See T3684.
41
$path = $request->getPath();
42
43
Javelin::initBehavior(
44
'dark-console',
45
array(
46
'uri' => $path,
47
'key' => $console->getKey($request),
48
'color' => $console->getColor(),
49
'quicksand' => $request->isQuicksand(),
50
));
51
}
52
53
// Flatten the response first, so we initialize any behaviors and metadata
54
// we need to.
55
$content = array(
56
'payload' => $this->content,
57
);
58
$this->encodeJSONForHTTPResponse($content);
59
60
$response = CelerityAPI::getStaticResourceResponse();
61
62
if ($request) {
63
$viewer = $request->getViewer();
64
if ($viewer) {
65
$postprocessor_key = $viewer->getUserSetting(
66
PhabricatorAccessibilitySetting::SETTINGKEY);
67
if ($postprocessor_key !== null && strlen($postprocessor_key)) {
68
$response->setPostprocessorKey($postprocessor_key);
69
}
70
}
71
}
72
73
$object = $response->buildAjaxResponse(
74
$content['payload'],
75
$this->error);
76
77
$response_json = $this->encodeJSONForHTTPResponse($object);
78
return $this->addJSONShield($response_json);
79
}
80
81
public function getHeaders() {
82
$headers = array(
83
array('Content-Type', 'text/plain; charset=UTF-8'),
84
);
85
$headers = array_merge(parent::getHeaders(), $headers);
86
return $headers;
87
}
88
89
}
90
91