EXTMVC:
authorJochen Rau <j.rau@web.de>
Sun, 15 Mar 2009 08:06:59 +0000 (08:06 +0000)
committerJochen Rau <j.rau@web.de>
Sun, 15 Mar 2009 08:06:59 +0000 (08:06 +0000)
* settings are now injected to the controller
* extension, controller, action to be called can now be set via $_GET
* the ViewObjectName is now resolved in the ActionView
* the Action is now stored in uppercase in the WebRequest

typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_AbstractController.php
typo3/sysext/extbase/Classes/Controller/TX_EXTMVC_Controller_ActionController.php
typo3/sysext/extbase/Classes/View/Helper/TX_EXTMVC_View_Helper_LinkHelper.php
typo3/sysext/extbase/class.tx_extmvc_dispatcher.php

index 28efeec..bfea337 100755 (executable)
@@ -73,7 +73,7 @@ abstract class TX_EXTMVC_Controller_AbstractController implements TX_EXTMVC_Cont
         * Injects the settings of the extension.
         *
         * @param array $settings Settings container of the current extension
-        * @return void
+               * @return void
         */
        public function injectSettings(array $settings) {
                $this->settings = $settings;
@@ -139,7 +139,7 @@ abstract class TX_EXTMVC_Controller_AbstractController implements TX_EXTMVC_Cont
                $escapedUri = htmlentities($uri, ENT_QUOTES, 'utf-8');
                $this->response->setContent('<html><head><meta http-equiv="refresh" content="' . intval($delay) . ';url=' . $escapedUri . '"/></head></html>');
                $this->response->setStatus($statusCode);
-               $this->response->setHeader('Location', (string)$uri);
+               // $this->response->setHeader('Location', (string)$uri);
                throw new TX_EXTMVC_Exception_StopAction();
        }
 
index 76042a7..bb46723 100644 (file)
@@ -31,6 +31,11 @@ require_once(t3lib_extMgm::extPath('extmvc') . 'Classes/Exception/TX_EXTMVC_Exce
  */
 class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_AbstractController {
 
+       /**
+        * @var boolean If initializeView() should be called on an action invocation.
+        */
+       protected $initializeView = TRUE;
+
        /**
         * @var TX_EXTMVC_View_AbstractView By default a view with the same name as the current action is provided. Contains NULL if none was found.
         */
@@ -42,11 +47,18 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
         */
        protected $viewObjectName = NULL;
 
+       /**
+        * Pattern after which the view object name is built
+        *
+        * @var string
+        */
+       protected $viewObjectNamePattern = 'TX_@extension_View_@controller@action';
+
        /**
         * Name of the action method
         * @var string
         */
-       protected $actionMethodName = 'index';
+       protected $actionMethodName = 'indexAction';
        
        /**
         * Actions that schould not be cached (changes the invocated dispatcher to a USER_INT cObject)
@@ -69,7 +81,7 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
                $this->actionMethodName = $this->resolveActionMethodName();
                $this->initializeArguments();
                $this->mapRequestArgumentsToLocalArguments();
-               $this->initializeView();
+               if ($this->initializeView) $this->initializeView();
                $this->initializeAction();
 
                $this->callActionMethod();
@@ -120,12 +132,27 @@ class TX_EXTMVC_Controller_ActionController extends TX_EXTMVC_Controller_Abstrac
         * @return void
         */
        protected function initializeView() {
-               $viewObjectName = ($this->viewObjectName === NULL) ? $this->request->getViewObjectName() : $this->viewObjectName;
+               // TODO Reslove View Object name
+               $viewObjectName = ($this->viewObjectName === NULL) ? $this->resolveViewObjectName() : $this->viewObjectName;
                if ($viewObjectName === FALSE) $viewObjectName = 'TX_EXTMVC_View_EmptyView';
 
                $this->view = t3lib_div::makeInstance($viewObjectName);
                $this->view->setRequest($this->request);
        }
+       
+       /**
+        * Determines the fully qualified view object name.
+        *
+        * @return string The fully qualified view object name
+        */
+       protected function resolveViewObjectName() {
+               $possibleViewName = $this->viewObjectNamePattern;               
+               $extensionKey = $this->request->getControllerExtensionKey();
+               $possibleViewName = str_replace('@extension', $extensionKey, $possibleViewName);                
+               $possibleViewName = str_replace('@controller', $this->request->getControllerName(), $possibleViewName);         
+               $possibleViewName = str_replace('@action', ucfirst($this->request->getControllerActionName()), $possibleViewName);              
+               return $possibleViewName;
+       }
 
        /**
         * Initializes the controller before invoking an action method.
index c3b43e8..98c7774 100644 (file)
@@ -48,7 +48,7 @@ class TX_EXTMVC_View_Helper_LinkHelper extends TX_EXTMVC_View_Helper_AbstractHel
 
        public function render($view, $content, $arguments, $templateResource, $variables) {
                $parameters = t3lib_div::_GET();
-               $prefixedExtensionKey = 'tx_' . $this->request->getControllerExtensionKey();
+               $prefixedExtensionKey = 'tx_' . strtolower($this->request->getControllerExtensionKey());
                if (!empty($arguments['to'])) {
                        $linkTo = $arguments['to'];
                        $view->replaceReferencesWithValues($linkTo, $variables);
index 446acbf..b126768 100644 (file)
@@ -79,17 +79,22 @@ class TX_EXTMVC_Dispatcher {
         * @param array|NULL $configuration The TS configuration array
         * @return String $content The processed content
         */
-       public function dispatch($content, $configuration) {                            
+       public function dispatch($content, $configuration) {
                // TODO Add an AJAX dispatcher
-               // debug($configuration);
+               $parameters = t3lib_div::_GET('tx_extmvc');
+               // TODO Is stripslashes secure enough?
+               $extensionKey = isset($parameters['extension']) ? stripslashes($parameters['extension']) : $configuration['extension'];
+               $controller = isset($parameters['controller']) ? stripslashes($parameters['controller']) : $configuration['controller'];
+               $action = isset($parameters['action']) ? stripslashes($parameters['action']) : $configuration['action'];
+               
                $request = t3lib_div::makeInstance('TX_EXTMVC_Web_Request');
                $request->setRequestURI(t3lib_div::getIndpEnv('TYPO3_REQUEST_URL'));
                $request->setBaseURI(t3lib_div::getIndpEnv('TYPO3_SITE_URL'));
-               $request->setControllerExtensionKey(strtolower($configuration['extension']));
-               $request->setControllerName($configuration['controller']);
-               $request->setControllerActionName($configuration['action']);
+               $request->setControllerExtensionKey($extensionKey);
+               $request->setControllerName($controller);
+               $request->setControllerActionName($action);
                $arguments = t3lib_div::makeInstance('TX_EXTMVC_Controller_Arguments');
-               foreach (t3lib_div::GParrayMerged('tx_' . strtolower($configuration['extension'])) as $key => $value) {
+               foreach (t3lib_div::GParrayMerged('tx_' . strtolower($extensionKey)) as $key => $value) {
                        $argument = new TX_EXTMVC_Controller_Argument($key, 'Raw');
                        $argument->setValue($value);
                        $arguments->addArgument($argument);
@@ -101,9 +106,10 @@ class TX_EXTMVC_Dispatcher {
                $controller = t3lib_div::makeInstance($controllerObjectName);
                
                if (!$controller instanceof TX_EXTMVC_Controller_AbstractController) throw new TX_EXTMVC_Exception_InvalidController('Invalid controller "' . $controllerObjectName . '". The controller must be a valid request handling controller.', 1202921619);
-               // TODO Configuration management
-               // $settings = $this->configurationManager->getSettings($extensionKey);
-               // $controller->injectSettings($this->configurationManager->getSettings($request->getControllerExtensionKey()));
+
+               $settings = is_array($configuration['settings.']) ? $configuration['settings.'] : array();
+               $controller->injectSettings($settings);
+
                $session = t3lib_div::makeInstance('TX_EXTMVC_Persistence_Session');
                try {
                        $controller->processRequest($request, $response);