]> git.mxchange.org Git - core.git/blobdiff - framework/main/classes/resolver/command/class_BaseCommandResolver.php
Some updates:
[core.git] / framework / main / classes / resolver / command / class_BaseCommandResolver.php
index 7b77bdce213f53b12349fcc938f070b1a9e79c70..6c463cd3368e3f5add1baf5b820b096fe7d78d58 100644 (file)
@@ -1,21 +1,29 @@
 <?php
 // Own namespace
-namespace CoreFramework\Resolver\Command;
+namespace Org\Mxchange\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;
+use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap;
+use Org\Mxchange\CoreFramework\Command\Commandable;
+use Org\Mxchange\CoreFramework\Command\InvalidCommandException;
+use Org\Mxchange\CoreFramework\Factory\ObjectFactory;
+use Org\Mxchange\CoreFramework\Request\Requestable;
+use Org\Mxchange\CoreFramework\Resolver\BaseResolver;
+
+// Import SPL stuff
+use \InvalidArgumentException;
+use \UnexpectedValueException;
 
 /**
  * A generic command resolver class
  *
  * @author             Roland Haeder <webmaster@shipsimu.org>
  * @version            0.0.0
+<<<<<<< HEAD:framework/main/classes/resolver/command/class_BaseCommandResolver.php
  * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
+=======
+ * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2016 Core Developer Team
+>>>>>>> Some updates::inc/main/classes/resolver/command/class_BaseCommandResolver.php
  * @license            GNU GPL 3.0 or any newer version
  * @link               http://www.shipsimu.org
  *
@@ -32,7 +40,7 @@ use CoreFramework\Resolver\BaseResolver;
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
-class BaseCommandResolver extends BaseResolver {
+abstract class BaseCommandResolver extends BaseResolver {
        /**
         * Protected constructor
         *
@@ -86,10 +94,8 @@ class BaseCommandResolver extends BaseResolver {
         *
         * @param       $requestInstance        An instance of a Requestable class
         * @return      $commandInstance        An instance of the resolved command
-        * @throws      InvalidCommandException                         Thrown if $commandName is
-        *                                                                                              invalid
-        * @throws      InvalidCommandInstanceException         Thrown if $commandInstance
-        *                                                                                              is an invalid instance
+        * @throws      InvalidCommandException         Thrown if $commandName is invalid
+        * @throws      UnexpectedValueException        Thrown if $commandInstance is an invalid instance
         */
        public function resolveCommandByRequest (Requestable $requestInstance) {
                // Init variables
@@ -101,11 +107,11 @@ class BaseCommandResolver extends BaseResolver {
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) {
-                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . self::getResponseTypeFromSystem() . '_command');
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command');
                } // END - if
 
                // Check if command is valid
-               if ($this->isCommandValid($this->getNamespace(), $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
@@ -116,7 +122,7 @@ class BaseCommandResolver extends BaseResolver {
                // And validate it
                if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) {
                        // This command has an invalid instance!
-                       throw new InvalidCommandInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
+                       throw new UnexpectedValueException(sprintf('commandInstance for commandName=%s is not object (%s) or does not implement Commandable.', $commandName, gettype($commandInstance)), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
 
                // Set last command
@@ -139,11 +145,11 @@ class BaseCommandResolver extends BaseResolver {
 
                // Is the command empty? Then fall back to default command
                if (empty($commandName)) {
-                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . self::getResponseTypeFromSystem() . '_command');
+                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . FrameworkBootstrap::getRequestTypeFromSystem() . '_command');
                } // END - if
 
                // Check if command is valid
-               if ($this->isCommandValid($commandName) === FALSE) {
+               if ($this->isCommandValid($commandName) === false) {
                        // This command is invalid!
                        throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
                } // END - if
@@ -161,19 +167,19 @@ class BaseCommandResolver extends BaseResolver {
         * @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
+        * @throws      InvalidArgumentException        Thrown if given command is not set
         */
        protected function isCommandValid ($namespace, $commandName) {
                // By default nothing shall be valid
-               $isValid = FALSE;
+               $isValid = false;
 
                // 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);
+                       throw new InvalidArgumentException('Parameter "namespace" is empty');
                } elseif (empty($commandName)) {
                        // Then thrown an exception here
-                       throw new EmptyVariableException(array($this, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING);
+                       throw new InvalidArgumentException('Parameter "commandName" is empty');
                } // END - if
 
                // Create the full class name
@@ -190,7 +196,7 @@ class BaseCommandResolver extends BaseResolver {
                // Is this class already loaded?
                if (class_exists($this->getClassName())) {
                        // This class does exist. :-)
-                       $isValid = TRUE;
+                       $isValid = true;
                } // END - if
 
                // Set command name