From: Roland Häder Date: Wed, 7 May 2008 14:57:06 +0000 (+0000) Subject: More renamed X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6de36357d5ad2ef5ff14094f180894492420c9bf;p=shipsimu.git More renamed --- diff --git a/.gitattributes b/.gitattributes index f0c126e..6b382e1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -285,9 +285,9 @@ inc/classes/main/request/.htaccess -text inc/classes/main/request/class_HttpRequest.php -text inc/classes/main/resolver/.htaccess -text inc/classes/main/resolver/class_BaseResolver.php -text -inc/classes/main/resolver/local/.htaccess -text -inc/classes/main/resolver/local/class_LocalCommandResolver.php -text -inc/classes/main/resolver/local/class_LocalControllerResolver.php -text +inc/classes/main/resolver/web/.htaccess -text +inc/classes/main/resolver/web/class_WebCommandResolver.php -text +inc/classes/main/resolver/web/class_WebControllerResolver.php -text inc/classes/main/response/.htaccess -text inc/classes/main/response/class_HttpResponse.php -text inc/classes/main/template/.htaccess -text diff --git a/inc/classes/main/resolver/local/.htaccess b/inc/classes/main/resolver/local/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/inc/classes/main/resolver/local/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/inc/classes/main/resolver/local/class_LocalCommandResolver.php b/inc/classes/main/resolver/local/class_LocalCommandResolver.php deleted file mode 100644 index 87e0d69..0000000 --- a/inc/classes/main/resolver/local/class_LocalCommandResolver.php +++ /dev/null @@ -1,184 +0,0 @@ - - * @version 0.0.0 - * @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 - * - * 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 . - */ -class LocalCommandResolver extends BaseResolver implements CommandResolver { - /** - * Last successfull resolved command - */ - private $lastCommandInstance = ""; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription("Lokaler Kommandoauflöser"); - - // Create unique ID number - $this->createUniqueID(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - - // Set prefix to "Local" - $this->setCommandPrefix("Local"); - } - - /** - * Creates an instance of a local command resolver with a given default command - * - * @param $defaultCommand The default command we shall execute - * @param $appInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance - * @throws EmptyVariableException Thrown if the default command is not set - * @throws InvalidCommandException Thrown if the default command is invalid - */ - public final static function createLocalCommandResolver ($defaultCommand, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new LocalCommandResolver(); - - // Is the variable $defaultCommand set and the command is valid? - if (empty($defaultCommand)) { - // Then thrown an exception here - throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { - // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($appInstance); - - // Return the prepared instance - return $resolverInstance; - } - - /** - * Returns an command instance for a given request class or null if - * MissingArrayElementsException was thrown - * - * @param $requestInstance An instance of a request 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 resolvCommandByRequest (Requestable $requestInstance) { - // Init variables - $commandName = ""; - $commandInstance = null; - - // Test if the required parameter is set - try { - // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter")); - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command"); - - // Check if the command is valid - if (!$this->isCommandValid($commandName)) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // 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); - } - - // Set last command - $this->lastCommandInstance = $commandInstance; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } - - // Return the resolved command instance - return $commandInstance; - } - - /** - * "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!) - */ - private function loadCommand ($commandName) { - // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); - - // Init command instance - $commandInstance = null; - - // Create command class name - $class = sprintf("Local%sCommand", - ucfirst(strtolower($commandName)) - ); - - // Is this class loaded? - if (!class_exists($class)) { - // 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); - } - } - - // Initiate the command - $eval = sprintf("\$commandInstance = %s::create%s(\$this);", - $class, - $class - ); - - // Run the command - eval($eval); - - // Is the instance valid? - if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { - // Something is wrong - $commandInstance = null; - } - - // Return the result - return $commandInstance; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/resolver/local/class_LocalControllerResolver.php b/inc/classes/main/resolver/local/class_LocalControllerResolver.php deleted file mode 100644 index 9c94209..0000000 --- a/inc/classes/main/resolver/local/class_LocalControllerResolver.php +++ /dev/null @@ -1,189 +0,0 @@ - - * @version 0.0.0 - * @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 - * - * 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 . - */ -class LocalControllerResolver extends BaseResolver implements ControllerResolver { - /** - * Last successfull resolved controller - */ - private $lastControllerName = ""; - - /** - * Private constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription(""); - - // Create unique ID number - $this->createUniqueID(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - - // Set prefix to "Local" - $this->setCommandPrefix("Local"); - } - - /** - * Creates an instance of a resolver class with a given command - * - * @param $commandName The default command we shall execute - * @param $appInstance An instance of a manageable application helper class - * @return $resolverInstance The prepared command resolver instance - * @throws EmptyVariableException Thrown if the default command is not set - * @throws InvalidCommandException Thrown if the default command is invalid - */ - public final static function createLocalControllerResolver ($commandName, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new LocalControllerResolver(); - - // Is the variable $commandName set and the command is valid? - if (empty($commandName)) { - // Then thrown an exception here - throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($commandName)) { - // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Set the application instance - $resolverInstance->setApplicationInstance($appInstance); - - // Return the prepared instance - return $resolverInstance; - } - - /** - * Resolves the default controller of the given command - * - * @return $controllerInstance A controller instance for the default - * command - * @throws InvalidCommandException Thrown if $commandName is - * invalid - * @throws InvalidControllerInstanceException Thrown if $commandInstance - * is invalid - */ - public function resolveDefaultController () { - // Init variables - $commandName = ""; - $controllerInstance = null; - - // Try to resolv the command - try { - // Get the command name - $commandName = $this->getCommandName(); - - // Check if the command is valid - if (!$this->isCommandValid($commandName)) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $controllerInstance = $this->loadController($commandName); - - // And validate it - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // This command has an invalid instance! - throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); - } - - // Set last command - $this->lastCommandInstance = $controllerInstance; - } catch (MissingArrayElementsException $e) { - // Just catch it here... - } - - // Return the maybe resolved instance - return $controllerInstance; - } - - /** - * "Loads" a given controller and instances it if not yet cached - * - * @param $commandName A controller name we shall look for - * @return $controllerInstance A loaded controller instance - * @throws DefaultControllerException Thrown if even the default - * controller class is missing (bad!) - */ - private function loadController ($commandName) { - // Cache default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); - - // Init controller instance - $controllerInstance = null; - - // Default controller - $class = "LocalDefaultController"; - - // Generate the class name - if ($commandName != $defaultCommand) { - // Create controller class name - $class = sprintf("Local%sController", - ucfirst(strtolower($commandName)) - ); - } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { - // Yes, display news in home then set default controller with news - $class = "LocalDefaultNewsController"; - } - - // Is this class loaded? - if (!class_exists($class)) { - // Class not found, so try the default one or throw exception - if ($commandName != $defaultCommand) { - // Try the default controller - return $this->loadController($defaultCommand); - } else { - // Still not found? - throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); - } - } - - // Initiate the controller - $eval = sprintf("\$controllerInstance = %s::create%s(LocalCommandResolver::createLocalCommandResolver(\$commandName, \$this->getApplicationInstance()));", - $class, - $class - ); - - // Run the command - eval($eval); - - // Is the instance valid? - if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { - // Something is wrong - $controllerInstance = null; - } - - // Return the result - return $controllerInstance; - } -} - -// [EOF] -?> diff --git a/inc/classes/main/resolver/web/.htaccess b/inc/classes/main/resolver/web/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/resolver/web/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php new file mode 100644 index 0000000..30b31b5 --- /dev/null +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -0,0 +1,184 @@ + + * @version 0.0.0 + * @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 + * + * 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 . + */ +class WebCommandResolver extends BaseResolver implements CommandResolver { + /** + * Last successfull resolved command + */ + private $lastCommandInstance = ""; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Lokaler Kommandoauflöser"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Set prefix to "Web" + $this->setCommandPrefix("Web"); + } + + /** + * Creates an instance of a Web command resolver with a given default command + * + * @param $defaultCommand The default command we shall execute + * @param $appInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if the default command is not set + * @throws InvalidCommandException Thrown if the default command is invalid + */ + public final static function createWebCommandResolver ($defaultCommand, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new WebCommandResolver(); + + // Is the variable $defaultCommand set and the command is valid? + if (empty($defaultCommand)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($appInstance); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Returns an command instance for a given request class or null if + * MissingArrayElementsException was thrown + * + * @param $requestInstance An instance of a request 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 resolvCommandByRequest (Requestable $requestInstance) { + // Init variables + $commandName = ""; + $commandInstance = null; + + // Test if the required parameter is set + try { + // This goes fine so let's resolv the command + $commandName = $requestInstance->getRequestElement($this->getConfigInstance()->readConfig("command_parameter")); + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->readConfig("default_command"); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // 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); + } + + // Set last command + $this->lastCommandInstance = $commandInstance; + } catch (MissingArrayElementsException $e) { + // Just catch it here... + } + + // Return the resolved command instance + return $commandInstance; + } + + /** + * "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!) + */ + private function loadCommand ($commandName) { + // Cache default command + $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + + // Init command instance + $commandInstance = null; + + // Create command class name + $class = sprintf("Web%sCommand", + ucfirst(strtolower($commandName)) + ); + + // Is this class loaded? + if (!class_exists($class)) { + // 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); + } + } + + // Initiate the command + $eval = sprintf("\$commandInstance = %s::create%s(\$this);", + $class, + $class + ); + + // Run the command + eval($eval); + + // Is the instance valid? + if ((!is_object($commandInstance)) || (!$commandInstance instanceof Commandable)) { + // Something is wrong + $commandInstance = null; + } + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php new file mode 100644 index 0000000..c3bebd5 --- /dev/null +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -0,0 +1,189 @@ + + * @version 0.0.0 + * @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 + * + * 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 . + */ +class WebControllerResolver extends BaseResolver implements ControllerResolver { + /** + * Last successfull resolved controller + */ + private $lastControllerName = ""; + + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription(""); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Set prefix to "Web" + $this->setCommandPrefix("Web"); + } + + /** + * Creates an instance of a resolver class with a given command + * + * @param $commandName The default command we shall execute + * @param $appInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared command resolver instance + * @throws EmptyVariableException Thrown if the default command is not set + * @throws InvalidCommandException Thrown if the default command is invalid + */ + public final static function createWebControllerResolver ($commandName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new WebControllerResolver(); + + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif (!$resolverInstance->isCommandValid($commandName)) { + // Invalid command found + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($appInstance); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default + * command + * @throws InvalidCommandException Thrown if $commandName is + * invalid + * @throws InvalidControllerInstanceException Thrown if $commandInstance + * is invalid + */ + public function resolveDefaultController () { + // Init variables + $commandName = ""; + $controllerInstance = null; + + // Try to resolv the command + try { + // Get the command name + $commandName = $this->getCommandName(); + + // Check if the command is valid + if (!$this->isCommandValid($commandName)) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $controllerInstance = $this->loadController($commandName); + + // And validate it + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // This command has an invalid instance! + throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); + } + + // Set last command + $this->lastCommandInstance = $controllerInstance; + } catch (MissingArrayElementsException $e) { + // Just catch it here... + } + + // Return the maybe resolved instance + return $controllerInstance; + } + + /** + * "Loads" a given controller and instances it if not yet cached + * + * @param $commandName A controller name we shall look for + * @return $controllerInstance A loaded controller instance + * @throws DefaultControllerException Thrown if even the default + * controller class is missing (bad!) + */ + private function loadController ($commandName) { + // Cache default command + $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + + // Init controller instance + $controllerInstance = null; + + // Default controller + $class = "WebDefaultController"; + + // Generate the class name + if ($commandName != $defaultCommand) { + // Create controller class name + $class = sprintf("Web%sController", + ucfirst(strtolower($commandName)) + ); + } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { + // Yes, display news in home then set default controller with news + $class = "WebDefaultNewsController"; + } + + // Is this class loaded? + if (!class_exists($class)) { + // Class not found, so try the default one or throw exception + if ($commandName != $defaultCommand) { + // Try the default controller + return $this->loadController($defaultCommand); + } else { + // Still not found? + throw new DefaultControllerException($this, self::EXCEPTION_DEFAUL_CONTROLLER_GONE); + } + } + + // Initiate the controller + $eval = sprintf("\$controllerInstance = %s::create%s(WebCommandResolver::createWebCommandResolver(\$commandName, \$this->getApplicationInstance()));", + $class, + $class + ); + + // Run the command + eval($eval); + + // Is the instance valid? + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // Something is wrong + $controllerInstance = null; + } + + // Return the result + return $controllerInstance; + } +} + +// [EOF] +?>