[TASK] Improve error message in NotFoundView to identify source
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Mvc / Controller / ActionController.php
index 4b49ae3..4db549e 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2010-2012 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
+ *  (c) 2010-2013 Extbase Team (http://forge.typo3.org/projects/typo3v4-mvc)
  *  Extbase is a backport of TYPO3 Flow. All credits go to the TYPO3 Flow team.
  *  All rights reserved
  *
@@ -59,7 +59,14 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         * @var string
         * @api
         */
-       protected $viewObjectNamePattern = 'Tx_@extension_View_@controller_@action@format';
+       protected $viewObjectNamePattern = '@vendor\@extension\View\@controller\@action@format';
+
+       /**
+        * @var string
+        * @api
+        * @deprecated since Extbase 6.2, will be removed two versions later
+        */
+       protected $deprecatedViewObjectNamePattern = 'Tx_@extension_View_@controller_@action@format';
 
        /**
         * A list of formats and object names of the views which should render them.
@@ -98,6 +105,12 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
        protected $errorMethodName = 'errorAction';
 
        /**
+        * @var \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService
+        * @api
+        */
+       protected $mvcPropertyMappingConfigurationService;
+
+       /**
         * @param \TYPO3\CMS\Extbase\Reflection\ReflectionService $reflectionService
         * @return void
         */
@@ -114,6 +127,13 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
        }
 
        /**
+        * @param \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService $mvcPropertyMappingConfigurationService
+        */
+       public function injectMvcPropertyMappingConfigurationService(\TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService $mvcPropertyMappingConfigurationService) {
+               $this->mvcPropertyMappingConfigurationService = $mvcPropertyMappingConfigurationService;
+       }
+
+       /**
         * Checks if the current request type is supported by the controller.
         *
         * If your controller only supports certain request types, either
@@ -145,11 +165,12 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                $this->request = $request;
                $this->request->setDispatched(TRUE);
                $this->response = $response;
-               $this->uriBuilder = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
+               $this->uriBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
                $this->uriBuilder->setRequest($request);
                $this->actionMethodName = $this->resolveActionMethodName();
                $this->initializeActionMethodArguments();
                $this->initializeActionMethodValidators();
+               $this->mvcPropertyMappingConfigurationService->initializePropertyMappingConfigurationFromRequest($request, $this->arguments);
                $this->initializeAction();
                $actionInitializationMethodName = 'initialize' . ucfirst($this->actionMethodName);
                if (method_exists($this, $actionInitializationMethodName)) {
@@ -260,6 +281,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        }
                        $validationResult = $this->arguments->getValidationResults();
                        if (!$validationResult->hasErrors()) {
+                               $this->signalSlotDispatcher->dispatch(__CLASS__, 'beforeCallActionMethod', array('controllerName' => get_class($this), 'actionMethodName' => $this->actionMethodName, 'preparedArguments' => $preparedArguments));
                                $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
                        } else {
                                $methodTagsValues = $this->reflectionService->getMethodTagsValues(get_class($this), $this->actionMethodName);
@@ -280,13 +302,14 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                                        $shouldCallActionMethod = FALSE;
                                }
                                if ($shouldCallActionMethod) {
+                                       $this->signalSlotDispatcher->dispatch(__CLASS__, 'beforeCallActionMethod', array('controllerName' => get_class($this), 'actionMethodName' => $this->actionMethodName, 'preparedArguments' => $preparedArguments));
                                        $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
                                } else {
                                        $actionResult = call_user_func(array($this, $this->errorMethodName));
                                }
                        }
                } else {
-                       // @deprecated since Extbase 1.4.0, will be removed with Extbase 6.1
+                       // @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
                        $preparedArguments = array();
                        foreach ($this->arguments as $argument) {
                                $preparedArguments[] = $argument->getValue();
@@ -294,6 +317,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        if ($this->argumentsMappingResults->hasErrors()) {
                                $actionResult = call_user_func(array($this, $this->errorMethodName));
                        } else {
+                               $this->signalSlotDispatcher->dispatch(__CLASS__, 'beforeCallActionMethod', array('controllerName' => get_class($this), 'actionMethodName' => $this->actionMethodName, 'preparedArguments' => $preparedArguments));
                                $actionResult = call_user_func_array(array($this, $this->actionMethodName), $preparedArguments);
                        }
                }
@@ -318,7 +342,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                $viewObjectName = $this->resolveViewObjectName();
                if ($viewObjectName !== FALSE) {
                        /** @var $view \TYPO3\CMS\Extbase\Mvc\View\ViewInterface */
-                       $view = $this->objectManager->create($viewObjectName);
+                       $view = $this->objectManager->get($viewObjectName);
                        $this->setViewConfiguration($view);
                        if ($view->canRender($this->controllerContext) === FALSE) {
                                unset($view);
@@ -326,15 +350,16 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                }
                if (!isset($view) && $this->defaultViewObjectName != '') {
                        /** @var $view \TYPO3\CMS\Extbase\Mvc\View\ViewInterface */
-                       $view = $this->objectManager->create($this->defaultViewObjectName);
+                       $view = $this->objectManager->get($this->defaultViewObjectName);
                        $this->setViewConfiguration($view);
                        if ($view->canRender($this->controllerContext) === FALSE) {
                                unset($view);
                        }
                }
                if (!isset($view)) {
-                       $view = $this->objectManager->create('TYPO3\\CMS\\Extbase\\Mvc\\View\\NotFoundView');
-                       $view->assign('errorMessage', 'No template was found. View could not be resolved for action "' . $this->request->getControllerActionName() . '"');
+                       $view = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\View\\NotFoundView');
+                       $view->assign('errorMessage', 'No template was found. View could not be resolved for action "'
+                               . $this->request->getControllerActionName() . '" in class "' . $this->request->getControllerObjectName() . '"');
                }
                $view->setControllerContext($this->controllerContext);
                if (method_exists($view, 'injectSettings')) {
@@ -372,7 +397,14 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         * @api
         */
        protected function resolveViewObjectName() {
-               $possibleViewName = $this->viewObjectNamePattern;
+               $vendorName = $this->request->getControllerVendorName();
+
+               if ($vendorName !== NULL) {
+                       $possibleViewName = str_replace('@vendor', $vendorName, $this->viewObjectNamePattern);
+               } else {
+                       $possibleViewName = $this->deprecatedViewObjectNamePattern;
+               }
+
                $extensionName = $this->request->getControllerExtensionName();
                $possibleViewName = str_replace('@extension', $extensionName, $possibleViewName);
                $possibleViewName = str_replace('@controller', $this->request->getControllerName(), $possibleViewName);
@@ -431,7 +463,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
                        $errorFlashMessage = $this->getErrorFlashMessage();
                        if ($errorFlashMessage !== FALSE) {
-                               $this->flashMessageContainer->add($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $this->controllerContext->getFlashMessageQueue()->addMessage(new \TYPO3\CMS\Core\Messaging\FlashMessage($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR));
                        }
                        $referringRequest = $this->request->getReferringRequest();
                        if ($referringRequest !== NULL) {
@@ -448,11 +480,11 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        }
                        return $message;
                } else {
-                       // @deprecated since Extbase 1.4.0, will be removed in Extbase 6.1
+                       // @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
                        $this->request->setErrors($this->argumentsMappingResults->getErrors());
                        $errorFlashMessage = $this->getErrorFlashMessage();
                        if ($errorFlashMessage !== FALSE) {
-                               $this->flashMessageContainer->add($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+                               $this->controllerContext->getFlashMessageQueue()->addMessage(new \TYPO3\CMS\Core\Messaging\FlashMessage($errorFlashMessage, '', \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR));
                        }
                        $referrer = $this->request->getInternalArgument('__referrer');
                        if ($referrer !== NULL) {
@@ -474,7 +506,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         * display no flash message at all on errors. Override this to customize
         * the flash message in your action controller.
         *
-        * @return string|boolean The flash message or FALSE if no flash message should be set
+        * @return string The flash message or FALSE if no flash message should be set
         * @api
         */
        protected function getErrorFlashMessage() {
@@ -488,7 +520,7 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
         *
         * @return void
         * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidOrNoRequestHashException In case request hash checking failed
-        * @deprecated since Extbase 1.4.0, will be removed in Extbase 6.1
+        * @deprecated since Extbase 1.4.0, will be removed two versions after Extbase 6.1
         */
        protected function checkRequestHash() {
                if ($this->configurationManager->isFeatureEnabled('rewrittenPropertyMapper')) {
@@ -532,6 +564,28 @@ class ActionController extends \TYPO3\CMS\Extbase\Mvc\Controller\AbstractControl
                        }
                }
        }
+
+       /**
+        * Returns a map of action method names and their parameters.
+        *
+        * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
+        * @return array Array of method parameters by action name
+        */
+       static public function getActionMethodParameters($objectManager) {
+               $reflectionService = $objectManager->get('TYPO3\CMS\Extbase\Reflection\ReflectionService');
+
+               $result = array();
+
+               $className = get_called_class();
+               $methodNames = get_class_methods($className);
+               foreach ($methodNames as $methodName) {
+                       if (strlen($methodName) > 6 && strpos($methodName, 'Action', strlen($methodName) - 6) !== FALSE) {
+                               $result[$methodName] = $reflectionService->getMethodParameters($className, $methodName);
+                       }
+               }
+
+               return $result;
+       }
 }
 
-?>
\ No newline at end of file
+?>