]> git.mxchange.org Git - core.git/blobdiff - inc/main/classes/resolver/command/class_BaseCommandResolver.php
Continued:
[core.git] / inc / main / classes / resolver / command / class_BaseCommandResolver.php
index 7bfa17a2fb6b4e6e00bf2ba37a7a741ae01bb536..7b77bdce213f53b12349fcc938f070b1a9e79c70 100644 (file)
@@ -1,6 +1,14 @@
 <?php
 // Own namespace
-namespace CoreFramework\Resolver\Controller;
+namespace CoreFramework\Resolver\Command;
+
+// Import framework stuff
+use CoreFramework\Command\Commandable;
+use CoreFramework\Command\InvalidCommandException;
+use CoreFramework\Factory\ObjectFactory;
+use CoreFramework\Generic\EmptyVariableException;
+use CoreFramework\Request\Requestable;
+use CoreFramework\Resolver\BaseResolver;
 
 /**
  * A generic command resolver class
@@ -49,7 +57,12 @@ class BaseCommandResolver extends BaseResolver {
                $commandInstance = NULL;
 
                // Create class name
-               $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command';
+               $className = sprintf(
+                       '%s\%s%sCommand',
+                       $this->getNamespace(),
+                       $this->getCapitalizedClassPrefix(),
+                       self::convertToClassName($commandName)
+               );
 
                // Create command class name
                $this->setClassName($className);
@@ -71,7 +84,7 @@ class BaseCommandResolver extends BaseResolver {
         * Returns an command instance for a given request class or null if
         * it was not found
         *
-        * @param       $requestInstance        An instance of a request class
+        * @param       $requestInstance        An instance of a Requestable class
         * @return      $commandInstance        An instance of the resolved command
         * @throws      InvalidCommandException                         Thrown if $commandName is
         *                                                                                              invalid
@@ -92,7 +105,7 @@ class BaseCommandResolver extends BaseResolver {
                } // END - if
 
                // Check if command is valid
-               if ($this->isCommandValid($commandName) === FALSE) {
+               if ($this->isCommandValid($this->getNamespace(), $commandName) === FALSE) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
@@ -145,22 +158,31 @@ class BaseCommandResolver extends BaseResolver {
        /**
         * Checks whether the given command is valid
         *
+        * @param       $namespace              Namespace to look in
         * @param       $commandName    The default command we shall execute
         * @return      $isValid                Whether the given command is valid
         * @throws      EmptyVariableException  Thrown if given command is not set
         */
-       public function isCommandValid ($commandName) {
+       protected function isCommandValid ($namespace, $commandName) {
                // By default nothing shall be valid
                $isValid = FALSE;
 
-               // Is a command set?
-               if (empty($commandName)) {
+               // Is namespace and command name set?
+               if (empty($namespace)) {
+                       // Then thrown an exception here
+                       throw new EmptyVariableException(array($this, 'namespace'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+               } elseif (empty($commandName)) {
                        // Then thrown an exception here
                        throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
                } // END - if
 
                // Create the full class name
-               $className = $this->getCapitalizedClassPrefix() . self::convertToClassName($commandName) . 'Command';
+               $className = sprintf(
+                       '%s\%s%sCommand',
+                       $namespace,
+                       $this->getCapitalizedClassPrefix(),
+                       self::convertToClassName($commandName)
+               );
 
                // Now, let us create the full name of the command class
                $this->setClassName($className);