17 use Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
38 public function dispatch(ServerRequestInterface $request, ResponseInterface $response =
null): ResponseInterface
40 $targetIdentifier = $request->getAttribute(
'target');
42 $arguments = [$request];
45 $scanForResponse = !GeneralUtility::makeInstance(Features::class)
46 ->isFeatureEnabled(
'simplifiedControllerActionDispatching');
47 if ($scanForResponse) {
48 if (is_array($targetIdentifier)) {
49 $controllerActionName = implode(
'::', $targetIdentifier);
50 $targetReflection = new \ReflectionMethod($controllerActionName);
51 } elseif (is_string($targetIdentifier) && strpos($targetIdentifier,
'::') !==
false) {
52 $controllerActionName = $targetIdentifier;
53 $targetReflection = new \ReflectionMethod($controllerActionName);
54 } elseif (is_callable($targetIdentifier)) {
55 $controllerActionName =
'closure function';
56 $targetReflection = new \ReflectionFunction($targetIdentifier);
58 $controllerActionName = $targetIdentifier .
'::__invoke';
59 $targetReflection = new \ReflectionMethod($controllerActionName);
61 if ($targetReflection->getNumberOfParameters() >= 2) {
63 'Handing over second argument $response to controller action ' . $controllerActionName .
'() is deprecated and will be removed in TYPO3 v10.0.',
66 $arguments[] = $response;
70 return call_user_func_array($target, $arguments);
83 if (is_array($target)) {
87 if (is_object($target) && $target instanceof \Closure) {
92 if (is_string($target) && strpos($target,
':') ===
false) {
93 $targetObject = GeneralUtility::makeInstance($target);
94 if (!method_exists($targetObject,
'__invoke')) {
95 throw new \InvalidArgumentException(
'Object "' . $target .
'" doesn\'t implement an __invoke() method and cannot be used as target.', 1442431631);
101 if (is_string($target) && strpos($target,
'::') !==
false) {
102 list($className, $methodName) = explode(
'::', $target, 2);
103 $targetObject = GeneralUtility::makeInstance($className);
104 return [$targetObject, $methodName];
108 if (is_callable($target)) {
112 throw new \InvalidArgumentException(
'Invalid target for "' . $target .
'", as it is not callable.', 1425381442);