This method invokes json_encode to perform the encoding.
public static jsonEncode ( $value, $options ) : string | ||
return | string | encoded string |
/** * Displays the exceptions to the client-side TJavascriptLogger. * A HTTP 500 status code is sent and the stack trace is sent as JSON encoded. * @param Exception exception details. */ protected function displayException($exception) { if ($this->getApplication()->getMode() === TApplication::STATE_DEBUG) { $response = $this->getApplication()->getResponse(); $trace = $this->getExceptionStackTrace($exception); // avoid error on non-utf8 strings try { $trace = TJavaScript::jsonEncode($trace); } catch (Exception $e) { // strip everythin not 7bit ascii $trace = preg_replace('/[^(\\x20-\\x7F)]*/', '', serialize($trace)); } // avoid exception loop if headers have already been sent try { $response->setStatusCode(500, 'Internal Server Error'); } catch (Exception $e) { } $content = $response->createHtmlWriter(); $content->getWriter()->setBoundary(TActivePageAdapter::CALLBACK_ERROR_HEADER); $content->write($trace); } else { error_log("Error happened while processing an existing error:\n" . $exception->__toString()); header('HTTP/1.0 500 Internal Server Error', true, 500); } $this->getApplication()->getResponse()->flush(); }
/** * Renders the callback response by adding additional callback data and * javascript actions in the header and page state if required. * @param THtmlWriter html content writer. */ protected function renderResponse($writer) { Prado::trace("ActivePage renderResponse()", 'Prado\\Web\\UI\\ActiveControls\\TActivePageAdapter'); //renders all the defered render() calls. foreach ($this->_controlsToRender as $rid => $forRender) { $forRender[0]->render($forRender[1]); } $response = $this->getResponse(); //send response data in header if ($response->getHasAdapter()) { $responseData = $response->getAdapter()->getResponseData(); if ($responseData !== null) { $data = TJavaScript::jsonEncode($responseData); $this->appendContentPart($response, self::CALLBACK_DATA_HEADER, $data); } } //sends page state in header if (($handler = $this->getCallbackEventTarget()) !== null) { if ($handler->getActiveControl()->getClientSide()->getEnablePageStateUpdate()) { $pagestate = $this->getPage()->getClientState(); $this->appendContentPart($response, self::CALLBACK_PAGESTATE_HEADER, $pagestate); } } //safari must receive at least 1 byte of data. $writer->write(" "); //output the end javascript if ($this->getPage()->getClientScript()->hasEndScripts()) { $writer = $response->createHtmlWriter(); $this->getPage()->getClientScript()->renderEndScriptsCallback($writer); $this->getPage()->getCallbackClient()->evaluateScript($writer); } //output the actions $executeJavascript = $this->getCallbackClientHandler()->getClientFunctionsToExecute(); $actions = TJavaScript::jsonEncode($executeJavascript); $this->appendContentPart($response, self::CALLBACK_ACTION_HEADER, $actions); $cs = $this->Page->getClientScript(); // collect all stylesheet file references $stylesheets = $cs->getStyleSheetUrls(); if (count($stylesheets) > 0) { $this->appendContentPart($response, self::CALLBACK_STYLESHEETLIST_HEADER, TJavaScript::jsonEncode($stylesheets)); } // collect all stylesheet snippets references $stylesheets = $cs->getStyleSheetCodes(); if (count($stylesheets) > 0) { $this->appendContentPart($response, self::CALLBACK_STYLESHEET_HEADER, TJavaScript::jsonEncode($stylesheets)); } // collect all script file references $scripts = $cs->getScriptUrls(); if (count($scripts) > 0) { $this->appendContentPart($response, self::CALLBACK_SCRIPTLIST_HEADER, TJavaScript::jsonEncode($scripts)); } // collect all hidden field references $fields = $cs->getHiddenFields(); if (count($fields) > 0) { $this->appendContentPart($response, self::CALLBACK_HIDDENFIELDLIST_HEADER, TJavaScript::jsonEncode($fields)); } }
/** * Renders content provided by TJsonResponse::getJsonContent() as * javascript in JSON format. */ protected function createJsonResponse($service, $properties, $config) { // init service properties foreach ($properties as $name => $value) { $service->setSubproperty($name, $value); } $service->init($config); //send content if not null if (($content = $service->getJsonContent()) !== null) { $response = $this->getResponse(); $response->setContentType('application/json'); $response->setCharset('UTF-8'); //send content $response->write(TJavaScript::jsonEncode($content)); } }
public function renderContents($writer) { $readyscript = 'jQuery(document).trigger(' . TJavaScript::quoteString('captchaready:' . $this->getClientID()) . ')'; $cs = $this->Page->ClientScript; $id = $this->getClientID(); $divid = $id . '_1_recaptchadiv'; $writer->write('<div id="' . htmlspecialchars($divid) . '">'); if (!$this->Page->IsCallback) { $writer->write(TJavaScript::renderScriptBlock('var RecaptchaOptions = ' . TJavaScript::jsonEncode($this->getClientSideOptions()) . ';')); $html = $this->recaptcha_get_html($this->getPublicKey()); /* reCAPTCHA currently does not support multiple validations per page $html = str_replace( array(self::ChallengeFieldName,self::ResponseFieldName), array($this->getChallengeFieldName(),$this->getResponseFieldName()), $html ); */ $writer->write($html); $cs->registerEndScript('ReCaptcha::EventScript', 'jQuery(document).ready(function() { ' . $readyscript . '; } );'); } else { $options = $this->getClientSideOptions(); $options['callback'] = new TJavaScriptLiteral('function() { ' . $readyscript . '; ' . $this->getCallbackScript() . '; }'); $cs->registerScriptFile('ReCaptcha::AjaxScript', self::RECAPTCHA_JS); $cs->registerEndScript('ReCaptcha::CreateScript::' . $id, implode(' ', array('if (!jQuery(' . TJavaScript::quoteString('#' . $this->getResponseFieldName()) . '))', '{', 'Recaptcha.destroy();', 'Recaptcha.create(', TJavaScript::quoteString($this->getPublicKey()) . ', ', TJavaScript::quoteString($divid) . ', ', TJavaScript::encode($options), ');', '}'))); } $writer->write('</div>'); }