[TASK] Have eIDs with PSR-7 without ControllerInterface
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Controller / ExtDirectEidController.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Controller;
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 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Frontend\Utility\EidUtility;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Core\Http\AjaxRequestHandler;
22
23 /**
24 * eID controller for ExtDirect
25 */
26 class ExtDirectEidController {
27
28 /**
29 * Ajax Instance
30 *
31 * @var AjaxRequestHandler
32 */
33 protected $ajaxObject = NULL;
34
35 /**
36 * Routes the given eID action to the related ExtDirect method with the necessary
37 * ajax object.
38 *
39 * @param string $ajaxID
40 * @return void
41 */
42 protected function routeAction($ajaxID) {
43 EidUtility::initLanguage();
44 $ajaxScript = $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['ExtDirect::' . $ajaxID]['callbackMethod'];
45 $this->ajaxObject = GeneralUtility::makeInstance(AjaxRequestHandler::class, 'ExtDirect::' . $ajaxID);
46 $parameters = array();
47 GeneralUtility::callUserFunction($ajaxScript, $parameters, $this->ajaxObject, FALSE, TRUE);
48 }
49
50 /**
51 * Renders/Echoes the ajax output
52 *
53 * @param ServerRequestInterface $request
54 * @param ResponseInterface $response
55 * @return ResponseInterface|NULL
56 * @throws \InvalidArgumentException
57 */
58 public function processRequest(ServerRequestInterface $request, ResponseInterface $response) {
59 $action = isset($request->getParsedBody()['action'])
60 ? $request->getParsedBody()['action']
61 : (isset($request->getQueryParams()['action']) ? $request->getQueryParams()['action'] : '');
62 if (!in_array($action, array('route', 'getAPI'), TRUE)) {
63 return NULL;
64 }
65 $this->routeAction($action);
66 return $this->ajaxObject->render();
67 }
68
69 }