‪TYPO3CMS  9.5
AjaxDispatcher.php
Go to the documentation of this file.
1 <?php
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;
24 
30 {
34  protected ‪$classMap = [
35  'RemoteServer' => RemoteServer::class,
36  'MassActions' => MassActionHandler::class,
37  'Actions' => ActionHandler::class
38  ];
39 
44  public function ‪dispatch(ServerRequestInterface $request): ResponseInterface
45  {
46  $callStack = json_decode($request->getBody()->getContents());
47  if (!is_array($callStack)) {
48  $callStack = [$callStack];
49  }
50  $results = [];
51  foreach ($callStack as $call) {
52  $className = $this->classMap[$call->action];
53  $method = $call->method;
54  $parameters = $call->data;
55  $instance = GeneralUtility::makeInstance($className);
56  $results[] = $this->‪buildResultFromResponse(call_user_func_array([$instance, $method], $parameters), $call);
57  }
58  return (new ‪JsonResponse())->setPayload($results);
59  }
60 
67  protected function ‪buildResultFromResponse($responseFromMethod, $call)
68  {
69  $tmp = new \stdClass();
70  $tmp->action = $call->action;
71  $tmp->method = $call->method;
72  $tmp->result = $responseFromMethod;
73  $tmp->tid = $call->tid;
74  $tmp->type = $call->type;
75  return $tmp;
76  }
77 }
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\$classMap
‪array $classMap
Definition: AjaxDispatcher.php:33
‪TYPO3\CMS\Workspaces\Controller\Remote\MassActionHandler
Definition: MassActionHandler.php:29
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\dispatch
‪ResponseInterface dispatch(ServerRequestInterface $request)
Definition: AjaxDispatcher.php:43
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\buildResultFromResponse
‪stdClass buildResultFromResponse($responseFromMethod, $call)
Definition: AjaxDispatcher.php:66
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:43
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher
Definition: AjaxDispatcher.php:30
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:25
‪TYPO3\CMS\Workspaces\Controller\Remote\ActionHandler
Definition: ActionHandler.php:36
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:2
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45