Code merge from latest ship-simu code
[mailer.git] / inc / classes / main / resolver / web / class_WebControllerResolver.php
index c3bebd50f41c85f2f197b2fa634c23ccf8239cc0..9e50d94516dfe8a99b592f7a8a73b33257257eaa 100644 (file)
  */
 class WebControllerResolver extends BaseResolver implements ControllerResolver {
        /**
-        * Last successfull resolved controller
+        * Last successfull resolved controller (name)
         */
        private $lastControllerName = "";
 
        /**
-        * Private constructor
+        * Last successfull resolved controller (instance)
+        */
+       private $lastControllerInstance = null;
+
+       /**
+        * Protected constructor
         *
         * @return      void
         */
@@ -37,15 +42,11 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                parent::__construct(__CLASS__);
 
                // Set part description
-               $this->setObjectDescription("");
+               $this->setObjectDescription("Resolver for local web controllers");
 
                // Create unique ID number
                $this->createUniqueID();
 
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-
                // Set prefix to "Web"
                $this->setCommandPrefix("Web");
        }
@@ -89,7 +90,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
         * @throws      InvalidControllerInstanceException      Thrown if $commandInstance
         *                                                                                              is invalid
         */
-       public function resolveDefaultController () {
+       public function resolveCommandController () {
                // Init variables
                $commandName = "";
                $controllerInstance = null;
@@ -114,8 +115,8 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                                throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER);
                        }
 
-                       // Set last command
-                       $this->lastCommandInstance = $controllerInstance;
+                       // Set last controller
+                       $this->lastControllerInstance = $controllerInstance;
                } catch (MissingArrayElementsException $e) {
                        // Just catch it here...
                }
@@ -133,8 +134,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
         *                                                                              controller class is missing (bad!)
         */
        private function loadController ($commandName) {
+                // Debug message
+                //print("<strong>----- ".__METHOD__." -----</strong><pre>");
+                //debug_print_backtrace();
+                //print("</pre>");
+                //
+
                // Cache default command
-               $defaultCommand = $this->getConfigInstance()->readConfig("default_command");
+               $defaultCommand = $this->getConfigInstance()->readConfig('default_command');
 
                // Init controller instance
                $controllerInstance = null;
@@ -146,11 +153,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                if ($commandName != $defaultCommand) {
                        // Create controller class name
                        $class = sprintf("Web%sController",
-                               ucfirst(strtolower($commandName))
+                               $this->convertToClassName($commandName)
                        );
-               } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") {
+               } elseif ($this->getConfigInstance()->readConfig('home_with_news') == "Y") {
                        // Yes, display news in home then set default controller with news
                        $class = "WebDefaultNewsController";
+               } else {
+                       // No nes at "home" page
+                       $class = "WebDefaultController";
                }
 
                // Is this class loaded?