@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
at upstream/main 41 lines 865 B view raw
1<?php 2 3final 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}