]> git.mxchange.org Git - hub.git/blobdiff - inc/classes/main/resolver/web/class_WebControllerResolver.php
Code syncronized with shipsimu code base
[hub.git] / inc / classes / main / resolver / web / class_WebControllerResolver.php
index 16ad0c2c40dbbbcbfa2e7a46eeb7b352cbd6a97b..60dfcfe0f5271e3a3dd6d1c7c09c05bdfc5fd1aa 100644 (file)
  */
 class WebControllerResolver extends BaseResolver implements ControllerResolver {
        /**
-        * Last successfull resolved controller
+        * Last successfull resolved controller (name)
         */
        private $lastControllerName = "";
 
+       /**
+        * Last successfull resolved controller (instance)
+        */
+       private $lastControllerInstance = null;
+
        /**
         * Protected constructor
         *
@@ -36,16 +41,6 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set part description
-               $this->setObjectDescription("");
-
-               // Create unique ID number
-               $this->createUniqueID();
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
-
                // Set prefix to "Web"
                $this->setCommandPrefix("Web");
        }
@@ -89,7 +84,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 +109,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...
                }
@@ -125,7 +120,9 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
        }
 
        /**
-        * "Loads" a given controller and instances it if not yet cached
+        * "Loads" a given controller and instances it if not yet cached. If the
+        * controller was not found one of the default controllers will be used
+        * depending on wether news shall be displayed.
         *
         * @param       $commandName                    A controller name we shall look for
         * @return      $controllerInstance             A loaded controller instance
@@ -133,8 +130,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;
@@ -143,15 +146,20 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                $class = "WebDefaultController";
 
                // Generate the class name
+               //* DEBUG: */ echo __METHOD__.": Command=".$commandName;
                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";
                }
+               //* DEBUG: */ echo ", controller=".$class."<br />\n";
 
                // Is this class loaded?
                if (!class_exists($class)) {
@@ -163,22 +171,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver {
                                // Still not found?
                                throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE);
                        }
-               }
+               } // END - if
 
-               // Initiate the controller
-               $eval = sprintf("\$controllerInstance = %s::create%s(WebCommandResolver::createWebCommandResolver(\$commandName, \$this->getApplicationInstance()));",
-                       $class,
-                       $class
-               );
+               // Initiate the resolver and controller
+               $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($commandName, $this->getApplicationInstance()));
+               $controllerInstance = ObjectFactory::createObjectByName($class, array($resolverInstance));
 
-               // Run the command
-               eval($eval);
-
-               // Is the instance valid?
-               if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) {
-                       // Something is wrong
-                       $controllerInstance = null;
-               }
+               // Remove resolver
+               unset($resolverInstance);
 
                // Return the result
                return $controllerInstance;