052a2b56a26494a4579b59f75c83c675d7327998
[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\Core\Http\AjaxRequestHandler;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Frontend\Utility\EidUtility;
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 {
44 EidUtility::initLanguage();
45 $ajaxScript = $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['ExtDirect::' . $ajaxID]['callbackMethod'];
46 $this->ajaxObject = GeneralUtility::makeInstance(AjaxRequestHandler::class, 'ExtDirect::' . $ajaxID);
47 $parameters = array();
48 GeneralUtility::callUserFunction($ajaxScript, $parameters, $this->ajaxObject, false, true);
49 }
50
51 /**
52 * Renders/Echoes the ajax output
53 *
54 * @param ServerRequestInterface $request
55 * @param ResponseInterface $response
56 * @return ResponseInterface|NULL
57 * @throws \InvalidArgumentException
58 */
59 public function processRequest(ServerRequestInterface $request, ResponseInterface $response)
60 {
61 $action = isset($request->getParsedBody()['action'])
62 ? $request->getParsedBody()['action']
63 : (isset($request->getQueryParams()['action']) ? $request->getQueryParams()['action'] : '');
64 if (!in_array($action, array('route', 'getAPI'), true)) {
65 return null;
66 }
67 $this->routeAction($action);
68 return $this->ajaxObject->render();
69 }
70 }