TYPO3 CMS  TYPO3_8-7
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 
23 
28 {
32  protected $classMap = [
33  'RemoteServer' => RemoteServer::class,
34  'MassActions' => MassActionHandler::class,
35  'Actions' => ActionHandler::class
36  ];
37 
43  public function dispatch(ServerRequestInterface $request, ResponseInterface $response)
44  {
45  $callStack = \GuzzleHttp\json_decode($request->getBody()->getContents());
46  if (!is_array($callStack)) {
47  $callStack = [$callStack];
48  }
49  $results = [];
50  foreach ($callStack as $call) {
51  $className = $this->classMap[$call->action];
52  $method = $call->method;
53  $parameters = $call->data;
54  $instance = GeneralUtility::makeInstance($className);
55  $results[] = $this->buildResultFromResponse(call_user_func_array([$instance, $method], $parameters), $call);
56  }
57  $response->getBody()->write(json_encode($results));
58  return $response;
59  }
60 
67  protected function buildResultFromResponse($responseFromMethod, $call)
68  {
69  $tmp = new \stdClass();
70  $tmp->action = $call->action;
71  $tmp->debug = '';
72  $tmp->method = $call->method;
73  $tmp->result = $responseFromMethod;
74  $tmp->tid = $call->tid;
75  $tmp->type = $call->type;
76  return $tmp;
77  }
78 }
buildResultFromResponse($responseFromMethod, $call)
dispatch(ServerRequestInterface $request, ResponseInterface $response)
static makeInstance($className,... $constructorArguments)