[BUGFIX] Fix incorrect usage of nested ternary
[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\ControllerInterface;
20 use TYPO3\CMS\Frontend\Utility\EidUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22 use TYPO3\CMS\Core\Http\AjaxRequestHandler;
23
24 /**
25 * eID controller for ExtDirect
26 */
27 class ExtDirectEidController implements ControllerInterface {
28
29 /**
30 * Ajax Instance
31 *
32 * @var AjaxRequestHandler
33 */
34 protected $ajaxObject = NULL;
35
36 /**
37 * Routes the given eID action to the related ExtDirect method with the necessary
38 * ajax object.
39 *
40 * @param string $ajaxID
41 * @return void
42 */
43 protected function routeAction($ajaxID) {
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 * @return ResponseInterface|NULL
56 * @throws \InvalidArgumentException
57 */
58 public function processRequest(ServerRequestInterface $request) {
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 }