2 namespace TYPO3\CMS\Extbase\Mvc\Controller;
19 use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
150 throw new \TYPO3\CMS\Extbase\Mvc\Exception\UnsupportedRequestTypeException(get_class($this) .
' does not support requests of type "' . get_class($request) .
'". Supported types are: ' . implode(
' ', $this->supportedRequestTypes), 1187701131);
153 if ($response instanceof \TYPO3\CMS\Extbase\Mvc\Web\
Response && $request instanceof WebRequest) {
154 $response->setRequest($request);
157 $this->request->setDispatched(
true);
159 $this->uriBuilder = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder::class);
160 $this->uriBuilder->setRequest($request);
163 $this->initializeActionMethodValidators();
164 $this->mvcPropertyMappingConfigurationService->initializePropertyMappingConfigurationFromRequest($request, $this->arguments);
166 $actionInitializationMethodName =
'initialize' . ucfirst($this->actionMethodName);
167 if (method_exists($this, $actionInitializationMethodName)) {
168 call_user_func(array($this, $actionInitializationMethodName));
170 $this->mapRequestArgumentsToControllerArguments();
171 $this->controllerContext = $this->buildControllerContext();
172 $this->view = $this->resolveView();
173 if ($this->view !== null) {
176 $this->callActionMethod();
191 $methodParameters = $this->reflectionService->getMethodParameters(get_class($this), $this->actionMethodName);
192 foreach ($methodParameters as $parameterName => $parameterInfo) {
194 if (isset($parameterInfo[
'type'])) {
195 $dataType = $parameterInfo[
'type'];
196 }
elseif ($parameterInfo[
'array']) {
199 if ($dataType === null) {
200 throw new \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentTypeException(
'The argument type for parameter $' . $parameterName .
' of method ' . get_class($this) .
'->' . $this->actionMethodName .
'() could not be detected.', 1253175643);
202 $defaultValue = isset($parameterInfo[
'defaultValue']) ? $parameterInfo[
'defaultValue'] : null;
203 $this->arguments->addNewArgument($parameterName, $dataType, $parameterInfo[
'optional'] ===
false, $defaultValue);
217 protected function initializeActionMethodValidators()
225 $actionMethodParameters = static::getActionMethodParameters($this->objectManager);
226 if (isset($actionMethodParameters[$this->actionMethodName])) {
229 $methodParameters = array();
237 $parameterValidators = $this->validatorResolver->buildMethodArgumentsValidatorConjunctions(get_class($this), $this->actionMethodName, $methodParameters);
239 foreach ($this->arguments as $argument) {
240 $validator = $parameterValidators[$argument->getName()];
242 $baseValidatorConjunction = $this->validatorResolver->getBaseValidatorConjunction($argument->getDataType());
243 if (!empty($baseValidatorConjunction) && $validator instanceof AbstractCompositeValidator) {
244 $validator->addValidator($baseValidatorConjunction);
246 $argument->setValidator($validator);
260 throw new \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchActionException(
'An action "' .
$actionMethodName .
'" does not exist in controller "' . get_class($this) .
'".', 1186669086);
275 protected function callActionMethod()
277 $preparedArguments = array();
279 foreach ($this->arguments as $argument) {
280 $preparedArguments[] = $argument->getValue();
282 $validationResult = $this->arguments->getValidationResults();
283 if (!$validationResult->hasErrors()) {
285 $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
287 $methodTagsValues = $this->reflectionService->getMethodTagsValues(get_class($this), $this->actionMethodName);
288 $ignoreValidationAnnotations = array();
289 if (isset($methodTagsValues[
'ignorevalidation'])) {
290 $ignoreValidationAnnotations = $methodTagsValues[
'ignorevalidation'];
294 $shouldCallActionMethod =
true;
295 foreach ($validationResult->getSubResults() as $argumentName => $subValidationResult) {
296 if (!$subValidationResult->hasErrors()) {
299 if (array_search(
'$' . $argumentName, $ignoreValidationAnnotations) !==
false) {
302 $shouldCallActionMethod =
false;
305 if ($shouldCallActionMethod) {
307 $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
309 $actionResult = call_user_func(array($this, $this->errorMethodName));
313 if ($actionResult === null && $this->view instanceof ViewInterface) {
314 $this->response->appendContent($this->view->render());
315 }
elseif (is_string($actionResult) && $actionResult !==
'') {
316 $this->response->appendContent($actionResult);
317 }
elseif (is_object($actionResult) && method_exists($actionResult,
'__toString')) {
318 $this->response->appendContent((
string)$actionResult);
329 $this->signalSlotDispatcher->dispatch(__CLASS__,
'beforeCallActionMethod', array(get_class($this), $this->actionMethodName, $preparedArguments));
339 protected function resolveView()
342 if ($viewObjectName !==
false) {
344 $view = $this->objectManager->get($viewObjectName);
346 if (
$view->canRender($this->controllerContext) ===
false) {
350 if (!isset(
$view) && $this->defaultViewObjectName !=
'') {
352 $view = $this->objectManager->get($this->defaultViewObjectName);
354 if (
$view->canRender($this->controllerContext) ===
false) {
359 $view = $this->objectManager->get(\TYPO3\CMS\Extbase\Mvc\View\NotFoundView::class);
360 $view->assign(
'errorMessage',
'No template was found. View could not be resolved for action "'
361 . $this->request->getControllerActionName() .
'" in class "' . $this->request->getControllerObjectName() .
'"');
363 $view->setControllerContext($this->controllerContext);
364 if (method_exists(
$view,
'injectSettings')) {
365 $view->injectSettings($this->settings);
367 $view->initializeView();
369 $view->assign(
'settings', $this->settings);
382 $extbaseFrameworkConfiguration = $this->configurationManager->getConfiguration(
387 $viewFunctionName =
'setTemplateRootPaths';
388 if (method_exists($view, $viewFunctionName)) {
389 $setting =
'templateRootPaths';
390 $parameter = $this->
getViewProperty($extbaseFrameworkConfiguration, $setting);
393 $view->$viewFunctionName($parameter);
398 $viewFunctionName =
'setLayoutRootPaths';
399 if (method_exists($view, $viewFunctionName)) {
400 $setting =
'layoutRootPaths';
401 $parameter = $this->
getViewProperty($extbaseFrameworkConfiguration, $setting);
404 $view->$viewFunctionName($parameter);
409 $viewFunctionName =
'setPartialRootPaths';
410 if (method_exists($view, $viewFunctionName)) {
411 $setting =
'partialRootPaths';
412 $parameter = $this->
getViewProperty($extbaseFrameworkConfiguration, $setting);
415 $view->$viewFunctionName($parameter);
434 !empty($extbaseFrameworkConfiguration[
'view'][$setting])
435 && is_array($extbaseFrameworkConfiguration[
'view'][$setting])
438 $values = array_reverse($values,
true);
452 $vendorName = $this->request->getControllerVendorName();
453 if ($vendorName === null) {
457 $possibleViewName = str_replace(
466 $this->request->getControllerExtensionName(),
467 $this->request->getControllerName(),
468 ucfirst($this->request->getControllerActionName())
472 $format = $this->request->getFormat();
473 $viewObjectName = str_replace(
'@format', ucfirst($format), $possibleViewName);
474 if (class_exists($viewObjectName) ===
false) {
475 $viewObjectName = str_replace(
'@format',
'', $possibleViewName);
477 if (isset($this->viewFormatToObjectNameMap[$format]) && class_exists($viewObjectName) ===
false) {
478 $viewObjectName = $this->viewFormatToObjectNameMap[$format];
480 return class_exists($viewObjectName) ? $viewObjectName :
false;
542 if (isset($extbaseSettings[
'persistence'][
'enableAutomaticCacheClearing']) && $extbaseSettings[
'persistence'][
'enableAutomaticCacheClearing'] ===
'1') {
545 $this->cacheService->clearPageCache(array($pageUid));
559 if ($errorFlashMessage !==
false) {
574 return 'An error occurred while trying to call ' . get_class($this) .
'->' . $this->actionMethodName .
'()';
587 $referringRequest = $this->request->getReferringRequest();
588 if ($referringRequest !== null) {
590 $this->request->setOriginalRequest($originalRequest);
591 $this->request->setOriginalRequestMappingResults($this->arguments->getValidationResults());
593 $referringRequest->getControllerActionName(),
594 $referringRequest->getControllerName(),
595 $referringRequest->getControllerExtensionName(),
596 $referringRequest->getArguments()
610 $outputMessage =
'Validation failed while trying to call ' . get_class($this) .
'->' . $this->actionMethodName .
'().' . PHP_EOL;
611 return $outputMessage;
627 $className = get_called_class();
628 $methodNames = get_class_methods($className);
629 foreach ($methodNames as $methodName) {
630 if (strlen($methodName) > 6 && strpos($methodName,
'Action', strlen($methodName) - 6) !==
false) {
631 $result[$methodName] =
$reflectionService->getMethodParameters($className, $methodName);