Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/aphront/response/AphrontJSONResponse.php
12241 views
1
<?php
2
3
final class AphrontJSONResponse extends AphrontResponse {
4
5
private $content;
6
private $addJSONShield;
7
8
public function setContent($content) {
9
$this->content = $content;
10
return $this;
11
}
12
13
public function setAddJSONShield($should_add) {
14
$this->addJSONShield = $should_add;
15
return $this;
16
}
17
18
public function shouldAddJSONShield() {
19
if ($this->addJSONShield === null) {
20
return true;
21
}
22
return (bool)$this->addJSONShield;
23
}
24
25
public function buildResponseString() {
26
$response = $this->encodeJSONForHTTPResponse($this->content);
27
if ($this->shouldAddJSONShield()) {
28
$response = $this->addJSONShield($response);
29
}
30
return $response;
31
}
32
33
public function getHeaders() {
34
$headers = parent::getHeaders();
35
36
$headers[] = array('Content-Type', 'application/json');
37
38
return $headers;
39
}
40
41
}
42
43