‪TYPO3CMS  10.4
AjaxDispatcher.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
25 
31 {
35  protected ‪$classMap = [
36  'RemoteServer' => RemoteServer::class,
37  'MassActions' => MassActionHandler::class,
38  'Actions' => ActionHandler::class
39  ];
40 
45  public function ‪dispatch(ServerRequestInterface $request): ResponseInterface
46  {
47  $callStack = json_decode($request->getBody()->getContents());
48  if (!is_array($callStack)) {
49  $callStack = [$callStack];
50  }
51  $results = [];
52  foreach ($callStack as $call) {
53  $className = $this->classMap[$call->action];
54  $method = $call->method;
55  $parameters = $call->data;
56  $instance = GeneralUtility::makeInstance($className);
57  $results[] = $this->‪buildResultFromResponse($instance->$method(...$parameters), $call);
58  }
59  return (new ‪JsonResponse())->setPayload($results);
60  }
61 
68  protected function ‪buildResultFromResponse($responseFromMethod, $call)
69  {
70  $tmp = new \stdClass();
71  $tmp->action = $call->action;
72  $tmp->method = $call->method;
73  $tmp->result = $responseFromMethod;
74  $tmp->tid = $call->tid;
75  $tmp->type = $call->type;
76  return $tmp;
77  }
78 }
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\$classMap
‪array $classMap
Definition: AjaxDispatcher.php:34
‪TYPO3\CMS\Workspaces\Controller\Remote\MassActionHandler
Definition: MassActionHandler.php:30
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\dispatch
‪ResponseInterface dispatch(ServerRequestInterface $request)
Definition: AjaxDispatcher.php:44
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher\buildResultFromResponse
‪stdClass buildResultFromResponse($responseFromMethod, $call)
Definition: AjaxDispatcher.php:67
‪TYPO3\CMS\Workspaces\Controller\Remote\RemoteServer
Definition: RemoteServer.php:48
‪TYPO3\CMS\Workspaces\Controller\AjaxDispatcher
Definition: AjaxDispatcher.php:31
‪TYPO3\CMS\Core\Http\JsonResponse
Definition: JsonResponse.php:26
‪TYPO3\CMS\Workspaces\Controller\Remote\ActionHandler
Definition: ActionHandler.php:36
‪TYPO3\CMS\Workspaces\Controller
Definition: AjaxController.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46