Continued with renaming-season:
[core.git] / inc / main / classes / resolver / command / class_BaseCommandResolver.php
diff --git a/inc/main/classes/resolver/command/class_BaseCommandResolver.php b/inc/main/classes/resolver/command/class_BaseCommandResolver.php
deleted file mode 100644 (file)
index 7b77bdc..0000000
+++ /dev/null
@@ -1,203 +0,0 @@
-<?php
-// Own namespace
-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
- *
- * @author             Roland Haeder <webmaster@shipsimu.org>
- * @version            0.0.0
- * @copyright  Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
- * @license            GNU GPL 3.0 or any newer version
- * @link               http://www.shipsimu.org
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * 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 {
-       /**
-        * Protected constructor
-        *
-        * @param       $className      Name of the class
-        * @return      void
-        */
-       protected function __construct ($className) {
-               // Call parent constructor
-               parent::__construct($className);
-       }
-
-       /**
-        * "Loads" a given command and instances it if not yet cached
-        *
-        * @param       $commandName                            A command name we shall look for
-        * @return      $commandInstance                        A loaded command instance
-        * @throws      InvalidCommandException         Thrown if even the default
-        *                                                                              command class is missing (bad!)
-        */
-       protected function loadCommand ($commandName) {
-               // Init command instance
-               $commandInstance = NULL;
-
-               // Create class name
-               $className = sprintf(
-                       '%s\%s%sCommand',
-                       $this->getNamespace(),
-                       $this->getCapitalizedClassPrefix(),
-                       self::convertToClassName($commandName)
-               );
-
-               // Create command class name
-               $this->setClassName($className);
-
-               // Is this class loaded?
-               if (!class_exists($this->getClassName())) {
-                       // Class not found, so throw an exception
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Initiate the command
-               $commandInstance = ObjectFactory::createObjectByName($this->getClassName(), array($this));
-
-               // Return the result
-               return $commandInstance;
-       }
-
-       /**
-        * Returns an command instance for a given request class or null if
-        * it was not found
-        *
-        * @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
-        */
-       public function resolveCommandByRequest (Requestable $requestInstance) {
-               // Init variables
-               $commandName = '';
-               $commandInstance = NULL;
-
-               // This goes fine so let's resolve the command
-               $commandName = $requestInstance->getRequestElement('command');
-
-               // Is the command empty? Then fall back to default command
-               if (empty($commandName)) {
-                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . self::getResponseTypeFromSystem() . '_command');
-               } // END - if
-
-               // Check if command is valid
-               if ($this->isCommandValid($this->getNamespace(), $commandName) === FALSE) {
-                       // This command is invalid!
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Get the command
-               $commandInstance = $this->loadCommand($commandName);
-
-               // 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);
-               } // END - if
-
-               // Set last command
-               $this->setResolvedInstance($commandInstance);
-
-               // Return the resolved command instance
-               return $commandInstance;
-       }
-
-       /**
-        * Resolves the command by its direct name and returns an instance of its class
-        *
-        * @param       $commandName            The direct command name we shall resolve
-        * @return      $commandInstance        An instance of the command class
-        * @throws      InvalidCommandException         Thrown if $commandName is invalid
-        */
-       public function resolveCommand ($commandName) {
-               // Initiate the instance variable
-               $commandInstance = NULL;
-
-               // Is the command empty? Then fall back to default command
-               if (empty($commandName)) {
-                       $commandName = $this->getConfigInstance()->getConfigEntry('default_' . self::getResponseTypeFromSystem() . '_command');
-               } // END - if
-
-               // Check if command is valid
-               if ($this->isCommandValid($commandName) === FALSE) {
-                       // This command is invalid!
-                       throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND);
-               } // END - if
-
-               // Get the command
-               $commandInstance = $this->loadCommand($commandName);
-
-               // Return the instance
-               return $commandInstance;
-       }
-
-       /**
-        * 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
-        */
-       protected function isCommandValid ($namespace, $commandName) {
-               // By default nothing shall be valid
-               $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);
-               } 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 = sprintf(
-                       '%s\%s%sCommand',
-                       $namespace,
-                       $this->getCapitalizedClassPrefix(),
-                       self::convertToClassName($commandName)
-               );
-
-               // Now, let us create the full name of the command class
-               $this->setClassName($className);
-
-               // Is this class already loaded?
-               if (class_exists($this->getClassName())) {
-                       // This class does exist. :-)
-                       $isValid = TRUE;
-               } // END - if
-
-               // Set command name
-               $this->setCommandName($commandName);
-
-               // Return the result
-               return $isValid;
-       }
-
-}