]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/resolver/command/web/class_WebCommandResolver.php
- XHTML errors/warnings fixed in some pages
[shipsimu.git] / inc / classes / main / resolver / command / web / class_WebCommandResolver.php
index d1ee1e69418dbb79b734eec12c71dec7c2986969..ba8097492c1a51b8a33e31f3906d5695b8594c21 100644 (file)
@@ -1,10 +1,10 @@
 <?php
 /**
- * A command resolver for local (non-hubbed) commands
+ * A command resolver for local (non-hubbed) web commands
  *
  * @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
  *
@@ -25,7 +25,7 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
        /**
         * Last successfull resolved command
         */
-       private $lastCommandInstance = "";
+       private $lastCommandInstance = null;
 
        /**
         * Protected constructor
@@ -36,12 +36,6 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                // Call parent constructor
                parent::__construct(__CLASS__);
 
-               // Set part description
-               $this->setObjectDescription("Resolver for local web commands");
-
-               // Create unique ID number
-               $this->generateUniqueId();
-
                // Set prefix to "Web"
                $this->setCommandPrefix("Web");
        }
@@ -62,8 +56,8 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                // Is the variable $commandName set and the command is valid?
                if (empty($commandName)) {
                        // Then thrown an exception here
-                       throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
-               } elseif (!$resolverInstance->isCommandValid($commandName)) {
+                       throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif ($resolverInstance->isCommandValid($commandName) === false) {
                        // Invalid command found
                        throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND);
                }
@@ -95,10 +89,10 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                $commandName = $requestInstance->getRequestElement('page');
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Check if the command is valid
-               if (!$this->isCommandValid($commandName)) {
+               if ($this->isCommandValid($commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
@@ -131,10 +125,10 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
                $commandInstance = null;
 
                // Is the command empty? Then fall back to default command
-               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_command');
+               if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Check if the command is valid
-               if (!$this->isCommandValid($commandName)) {
+               if ($this->isCommandValid($commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
                }
@@ -156,30 +150,24 @@ class WebCommandResolver extends BaseCommandResolver implements CommandResolver
         */
        private function loadCommand ($commandName) {
                // Cache default command
-               $defaultCommand = $this->getConfigInstance()->readConfig('default_command');
+               $defaultCommand = $this->getConfigInstance()->readConfig('default_web_command');
 
                // Init command instance
                $commandInstance = null;
 
                // Create command class name
-               $className = sprintf("Web%sCommand",
+               $this->setClassName(sprintf("Web%sCommand",
                        $this->convertToClassName($commandName)
-               );
+               ));
 
                // Is this class loaded?
-               if (!class_exists($className)) {
-                       // Class not found, so try the default one or throw exception
-                       if ($commandName != $defaultCommand) {
-                               // Try the default command
-                               return $this->loadCommand($defaultCommand);
-                       } else {
-                               // Still not found?
-                               throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
-                       }
+               if (!class_exists($this->getClassName())) {
+                       // Class not found, so throw an exception
+                       throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
 
                // Initiate the command
-               $commandInstance = ObjectFactory::createObjectByName($className, array($this));
+               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
 
                // Return the result
                return $commandInstance;