]> 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 2446e6dc776b885ea3d370ff63c77b7cecb1cb79..5378006099a8c964f98d01ab13826f24133866bb 100644 (file)
@@ -51,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
@@ -62,7 +62,7 @@ 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_CONTROLLER);
                }
@@ -120,9 +120,6 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
         *                                                                              controller class is missing (bad!)
         */
        private function loadController ($controllerName) {
-                // Debug message
-                //* DEBUG: */ $this->debugBackTrace();
-
                // Cache default command
                $defaultController = $this->getConfigInstance()->readConfig('default_web_command');
 
@@ -154,11 +151,26 @@ class WebControllerResolver extends BaseControllerResolver implements Controller
                        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