2 namespace TYPO3\CMS\Core\Http;
56 <script type="text/javascript">
109 if (array_key_exists($key, $this->content)) {
110 $oldcontent = $this->content[$key];
113 unset($this->content[$key]);
114 }
elseif (!isset($key) || empty($key)) {
129 return $key && array_key_exists($key, $this->content) ? $this->content[$key] :
$this->content;
140 if (
ArrayUtility::inArray(array(
'plain',
'xml',
'json',
'jsonhead',
'jsonbody',
'javascript'), $format)) {
141 $this->contentFormat = $format;
166 $this->errorMessage = $errorMsg;
188 return $this->renderAsError();
190 switch ($this->contentFormat) {
194 return $this->renderAsJSON();
200 return $this->renderAsXML();
203 return $this->renderAsPlain();
213 protected function renderAsError()
218 ->withStatus(500,
' (AJAX)')
219 ->withHeader(
'Content-type',
'text/xml; charset=utf-8')
220 ->withHeader(
'X-JSON',
'false');
222 $response->getBody()->write(
'<t3err>' . htmlspecialchars($this->errorMessage) .
'</t3err>');
233 protected function renderAsPlain()
238 ->withHeader(
'Content-type',
'text/html; charset=utf-8')
239 ->withHeader(
'X-JSON',
'true');
241 $response->getBody()->write(implode(
'', $this->content));
252 protected function renderAsXML()
257 ->withHeader(
'Content-type',
'text/xml; charset=utf-8')
258 ->withHeader(
'X-JSON',
'true');
260 $response->getBody()->write(implode(
'', $this->content));
277 protected function renderAsJSON()
283 $content = json_encode($this->content);
285 if ($this->contentFormat ===
'jsonhead') {
305 $response->getBody()->write(str_replace(
'|', json_encode($this->content), $this->javascriptCallbackWrap));