[TASK] Cleanup and update language module
[Packages/TYPO3.CMS.git] / typo3 / sysext / lang / Classes / View / AbstractJsonView.php
1 <?php
2 namespace TYPO3\CMS\Lang\View;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Base class for JSON views
19 *
20 * @author Kai Vogel <k.vogel@reply.de>
21 */
22 abstract class AbstractJsonView extends \TYPO3\CMS\Extbase\Mvc\View\AbstractView {
23
24 /**
25 * @var \TYPO3\CMS\Extbase\Object\ObjectManager
26 * @inject
27 */
28 protected $objectManager;
29
30 /**
31 * Render template content
32 *
33 * @return void
34 */
35 public function render() {
36 $result = $this->getReponseData();
37 $this->sendResponse($result);
38 }
39
40 /**
41 * Returns the response data
42 *
43 * @return array The response data
44 */
45 abstract protected function getReponseData();
46
47 /**
48 * Send response to browser
49 *
50 * @param array $data The response data
51 * @return void
52 */
53 protected function sendResponse(array $data) {
54 $response = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Response::class);
55 $response->setHeader('Content-Type', 'application/json; charset=utf-8');
56 $response->setContent(json_encode($data));
57 $response->sendHeaders();
58 $response->send();
59 exit;
60 }
61
62 }