]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/resolver/controller/web/class_WebControllerResolver.php
Typos fixed and special command resolver are now possible
[shipsimu.git] / inc / classes / main / resolver / controller / web / class_WebControllerResolver.php
index 2b0c17dd8d00ef686abc2616ca869a073f2985e9..5378006099a8c964f98d01ab13826f24133866bb 100644 (file)
@@ -4,7 +4,7 @@
  *
  * @author             Roland Haeder <webmaster@ship-simu.org>
  * @version            0.0.0
- * @copyright  Copyright(c) 2007, 2008 Roland Haeder, this is free software
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, this is free software
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.ship-simu.org
  *
@@ -41,12 +41,6 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set part description
-               $this->setObjectDescription("Resolver for local web controllers");
-
-               // Create unique ID number
-               $this->generateUniqueId();
-
                // Set prefix to "Web"
                $this->setControllerPrefix("Web");
        }
@@ -57,8 +51,8 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
         * @param       $controllerName                         The controller we shall resolve
         * @param       $appInstance                            An instance of a manageable application helper class
         * @return      $resolverInstance                       The prepared controller resolver instance
-        * @throws      EmptyVariableException          Thrown if the default command is not set
-        * @throws      InvalidControllerException      Thrown if the default controller is invalid
+        * @throws      EmptyVariableException          Thrown if default command is not set
+        * @throws      InvalidControllerException      Thrown if default controller is invalid
         */
        public final static function createWebControllerResolver ($controllerName, ManageableApplication $appInstance) {
                // Create the new instance
@@ -68,9 +62,9 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                if (empty($controllerName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif (!$resolverInstance->isControllerValid($controllerName)) {
+               } elseif ($resolverInstance->isControllerValid($controllerName) === false) {
                        // Invalid command found
-                       throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_COMMAND);
+                       throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                }
 
                // Set the application instance
@@ -122,21 +116,18 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
         *
         * @param       $controllerName                 A controller name we shall look for
         * @return      $controllerInstance             A loaded controller instance
-        * @throws      DefaultControllerException      Thrown if even the default
+        * @throws      InvalidControllerException      Thrown if even the requested
         *                                                                              controller class is missing (bad!)
         */
        private function loadController ($controllerName) {
-                // Debug message
-                //* DEBUG: */ $this->debugBacktrace();
-
                // Cache default command
-               $defaultController = $this->getConfigInstance()->readConfig('default_command');
+               $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Init controller instance
                $controllerInstance = null;
 
                // Default controller
-               $this->setClassName("WebDefaultController");
+               $this->setClassName('WebDefaultController');
 
                // Generate the class name
                //* DEBUG: */ echo __METHOD__.": Controller=".$controllerName;
@@ -147,30 +138,39 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                        ));
                } elseif ($this->getConfigInstance()->readConfig('page_with_news') == $this->getApplicationInstance()->getRequestInstance()->getRequestElement('page')) {
                        // Yes, display news in home then set default controller with news
-                       $this->setClassName("WebDefaultNewsController");
+                       $this->setClassName('WebDefaultNewsController');
                } else {
-                       // No news at "home" page or non-news page
-                       $this->setClassName("WebDefaultController");
+                       // No news at home page or non-news page
+                       $this->setClassName('WebDefaultController');
                }
                //* DEBUG: */ echo ", controller=".$this->getClassName()."<br />\n";
 
                // Is this class loaded?
                if (!class_exists($this->getClassName())) {
-                       // Class not found, so try the default one or throw exception
-                       if ($controllerName != $defaultController) {
-                               // Try the default controller
-                               return $this->loadController($defaultController);
-                       } else {
-                               // Still not found?
-                               throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE);
-                       }
+                       // Throw an exception here
+                       throw new InvalidControllerException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER);
                } // END - if
 
+               // Set default resolver config name
+               $resolverConfigEntry = "";
+
+               // Try to read a config entry for our resolver including controller name... ;-)
+               try {
+                       // Create the resolver name
+                       $resolverConfigEntry = sprintf("web_cmd_%s_resolver_class", strtolower($controllerName));
+
+                       // Get the config, this will throw an exception if there is no special command resolver
+                       $resolverClass = $this->getConfigInstance()->readConfig($resolverConfigEntry);
+               } catch (ConfigEntryNotFoundException $e) {
+                       // Use default resolver entry
+                       $resolverConfigEntry = "web_cmd_resolver_class";
+               }
+
                // Initiate the resolver and controller
-               $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($controllerName, $this->getApplicationInstance()));
+               $resolverInstance = ObjectFactory::createObjectByConfiguredName($resolverConfigEntry, array($controllerName, $this->getApplicationInstance()));
                $controllerInstance = ObjectFactory::createObjectByName($this->getClassName(), array($resolverInstance));
 
-               // Remove resolver
+               // Remove resolver (we don't need it anymore)
                unset($resolverInstance);
 
                // Return the result