Path: blob/master/src/aphront/response/AphrontAjaxResponse.php
12241 views
<?php12final class AphrontAjaxResponse extends AphrontResponse {34private $content;5private $error;6private $disableConsole;78public function setContent($content) {9$this->content = $content;10return $this;11}1213public function setError($error) {14$this->error = $error;15return $this;16}1718public function setDisableConsole($disable) {19$this->disableConsole = $disable;20return $this;21}2223private function getConsole() {24if ($this->disableConsole) {25$console = null;26} else {27$request = $this->getRequest();28$console = $request->getApplicationConfiguration()->getConsole();29}30return $console;31}3233public function buildResponseString() {34$request = $this->getRequest();35$console = $this->getConsole();36if ($console) {37// NOTE: We're stripping query parameters here both for readability and38// to mitigate BREACH and similar attacks. The parameters are available39// in the "Request" tab, so this should not impact usability. See T3684.40$path = $request->getPath();4142Javelin::initBehavior(43'dark-console',44array(45'uri' => $path,46'key' => $console->getKey($request),47'color' => $console->getColor(),48'quicksand' => $request->isQuicksand(),49));50}5152// Flatten the response first, so we initialize any behaviors and metadata53// we need to.54$content = array(55'payload' => $this->content,56);57$this->encodeJSONForHTTPResponse($content);5859$response = CelerityAPI::getStaticResourceResponse();6061if ($request) {62$viewer = $request->getViewer();63if ($viewer) {64$postprocessor_key = $viewer->getUserSetting(65PhabricatorAccessibilitySetting::SETTINGKEY);66if ($postprocessor_key !== null && strlen($postprocessor_key)) {67$response->setPostprocessorKey($postprocessor_key);68}69}70}7172$object = $response->buildAjaxResponse(73$content['payload'],74$this->error);7576$response_json = $this->encodeJSONForHTTPResponse($object);77return $this->addJSONShield($response_json);78}7980public function getHeaders() {81$headers = array(82array('Content-Type', 'text/plain; charset=UTF-8'),83);84$headers = array_merge(parent::getHeaders(), $headers);85return $headers;86}8788}899091