From: Roland Haeder Date: Mon, 23 Mar 2015 16:04:30 +0000 (+0100) Subject: Renamed more from 'web' to 'html'. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=a5841c2444775cb682ae962d6878439b75c8b211;p=shipsimu.git Renamed more from 'web' to 'html'. Signed-off-by: Roland Haeder --- diff --git a/application/shipsimu/main/controller/html/.htaccess b/application/shipsimu/main/controller/html/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/shipsimu/main/controller/html/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/shipsimu/main/controller/html/class_HtmlCompanyController.php b/application/shipsimu/main/controller/html/class_HtmlCompanyController.php new file mode 100644 index 0000000..741cc5a --- /dev/null +++ b/application/shipsimu/main/controller/html/class_HtmlCompanyController.php @@ -0,0 +1,106 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . + */ +class HtmlCompanyController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + * @todo Add some filters to this controller + */ + public static final function createHtmlCompanyController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new HtmlCompanyController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // User auth filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); + + // User update filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter')); + + // News fetcher filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter')); + + // News proccess/display-preparation + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter')); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Try to run the pre filters, if auth exceptions come through redirect here + try { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + } catch (UserAuthorizationException $e) { + // Redirect to main page + $responseInstance->redirectToConfiguredUrl('login_failed'); + + // Exit here + exit(); + } + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the pre filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } +} + +// [EOF] +?> diff --git a/application/shipsimu/main/controller/html/class_HtmlGovernmentFailedController.php b/application/shipsimu/main/controller/html/class_HtmlGovernmentFailedController.php new file mode 100644 index 0000000..217b6b5 --- /dev/null +++ b/application/shipsimu/main/controller/html/class_HtmlGovernmentFailedController.php @@ -0,0 +1,106 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . + */ +class HtmlGovernmentFailedController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + * @todo Add some filters to this controller + */ + public static final function createHtmlGovernmentFailedController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new HtmlGovernmentFailedController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // User auth filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); + + // User update filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter')); + + // News fetcher filter + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter')); + + // News proccess/display-preparation + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter')); + + // Return the prepared instance + return $controllerInstance; + } + + /** + * Handles the given request and response + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); + + // Add more filters by the command + $commandInstance->addExtraFilters($this, $requestInstance); + + // Try to run the pre filters, if auth exceptions come through redirect here + try { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + } catch (UserAuthorizationException $e) { + // Redirect to main page + $responseInstance->redirectToConfiguredUrl('login_failed'); + + // Exit here + exit(); + } + + // This request was valid! :-D + $requestInstance->requestIsValid(); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run the pre filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Flush the response out + $responseInstance->flushBuffer(); + } +} + +// [EOF] +?> diff --git a/application/shipsimu/main/controller/web/.htaccess b/application/shipsimu/main/controller/web/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/application/shipsimu/main/controller/web/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/shipsimu/main/controller/web/class_WebCompanyController.php b/application/shipsimu/main/controller/web/class_WebCompanyController.php deleted file mode 100644 index c5f1e2d..0000000 --- a/application/shipsimu/main/controller/web/class_WebCompanyController.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . - */ -class WebCompanyController extends BaseController implements Controller { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $controllerInstance A prepared instance of this class - * @todo Add some filters to this controller - */ - public static final function createWebCompanyController (CommandResolver $resolverInstance) { - // Create the instance - $controllerInstance = new WebCompanyController(); - - // Set the command resolver - $controllerInstance->setResolverInstance($resolverInstance); - - // User auth filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); - - // User update filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter')); - - // News fetcher filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter')); - - // News proccess/display-preparation - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter')); - - // Return the prepared instance - return $controllerInstance; - } - - /** - * Handles the given request and response - * - * @param $requestInstance An instance of a request class - * @param $responseInstance An instance of a response class - * @return void - */ - public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Try to run the pre filters, if auth exceptions come through redirect here - try { - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - } catch (UserAuthorizationException $e) { - // Redirect to main page - $responseInstance->redirectToConfiguredUrl('login_failed'); - - // Exit here - exit(); - } - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the pre filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); - } -} - -// [EOF] -?> diff --git a/application/shipsimu/main/controller/web/class_WebGovernmentFailedController.php b/application/shipsimu/main/controller/web/class_WebGovernmentFailedController.php deleted file mode 100644 index c51bf1c..0000000 --- a/application/shipsimu/main/controller/web/class_WebGovernmentFailedController.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . - */ -class WebGovernmentFailedController extends BaseController implements Controller { - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - } - - /** - * Creates an instance of this class - * - * @param $resolverInstance An instance of a command resolver class - * @return $controllerInstance A prepared instance of this class - * @todo Add some filters to this controller - */ - public static final function createWebGovernmentFailedController (CommandResolver $resolverInstance) { - // Create the instance - $controllerInstance = new WebGovernmentFailedController(); - - // Set the command resolver - $controllerInstance->setResolverInstance($resolverInstance); - - // User auth filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); - - // User update filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_update_filter')); - - // News fetcher filter - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_filter')); - - // News proccess/display-preparation - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_filter')); - - // Return the prepared instance - return $controllerInstance; - } - - /** - * Handles the given request and response - * - * @param $requestInstance An instance of a request class - * @param $responseInstance An instance of a response class - * @return void - */ - public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->getResolverInstance()->resolveCommandByRequest($requestInstance); - - // Add more filters by the command - $commandInstance->addExtraFilters($this, $requestInstance); - - // Try to run the pre filters, if auth exceptions come through redirect here - try { - // Run the pre filters - $this->executePreFilters($requestInstance, $responseInstance); - } catch (UserAuthorizationException $e) { - // Redirect to main page - $responseInstance->redirectToConfiguredUrl('login_failed'); - - // Exit here - exit(); - } - - // This request was valid! :-D - $requestInstance->requestIsValid(); - - // Execute the command - $commandInstance->execute($requestInstance, $responseInstance); - - // Run the pre filters - $this->executePostFilters($requestInstance, $responseInstance); - - // Flush the response out - $responseInstance->flushBuffer(); - } -} - -// [EOF] -?> diff --git a/application/shipsimu/main/resolver/command/.htaccess b/application/shipsimu/main/resolver/command/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/shipsimu/main/resolver/command/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/shipsimu/main/resolver/command/html/.htaccess b/application/shipsimu/main/resolver/command/html/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/shipsimu/main/resolver/command/html/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/shipsimu/main/resolver/command/html/class_HtmlCompanyCommandResolver.php b/application/shipsimu/main/resolver/command/html/class_HtmlCompanyCommandResolver.php new file mode 100644 index 0000000..e04768c --- /dev/null +++ b/application/shipsimu/main/resolver/command/html/class_HtmlCompanyCommandResolver.php @@ -0,0 +1,190 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . + */ +class HtmlCompanyCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Last successfull resolved command + */ + private $lastCommandInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "Html" + $this->setCommandPrefix('Html'); + } + + /** + * Creates an instance of a Html command resolver with a given default 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 default command is not set + * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable + */ + public static final function createHtmlCompanyCommandResolver ($commandName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new HtmlCompanyCommandResolver(); + + // Get request instance + $requestInstance = $appInstance->getRequestInstance(); + + // 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->resolveCommandByRequest($requestInstance) instanceof Commandable) { + // Invalid command found (missing interface?) + throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); + } + + // 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 + * it was not found + * + * @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 resolveCommandByRequest (Requestable $requestInstance) { + // Init instance + $commandInstance = null; + + // This goes fine so let's resolv the command + $commandName = str_replace('-', '_', $requestInstance->getRequestElement('app')) . '_' . $requestInstance->getRequestElement('page'); + + // Is there a "failed" request? + if ($requestInstance->isRequestElementSet('failed')) { + // Then include with within the command name + $commandName = $commandName . '_' . $requestInstance->getRequestElement('failed'); + } // END - if + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command'); + + // 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); + + // 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->lastCommandInstance = $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_web_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === false) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // Return the 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()->getConfigEntry('default_web_command'); + + // Init command instance + $commandInstance = null; + + // Get 'app' from the application + $app = Registry::getRegistry()->getInstance('application')->getRequestInstance()->getRequestElement('app'); + + // Create command class name + $this->setClassName(sprintf('%s%sCommand', + $this->getCommandPrefix(), + $this->convertToClassName($commandName) + )); + + // Is this class loaded? + 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($this->getClassName(), array($this)); + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/application/shipsimu/main/resolver/command/html/class_HtmlGovernmentFailedCommandResolver.php b/application/shipsimu/main/resolver/command/html/class_HtmlGovernmentFailedCommandResolver.php new file mode 100644 index 0000000..a83f222 --- /dev/null +++ b/application/shipsimu/main/resolver/command/html/class_HtmlGovernmentFailedCommandResolver.php @@ -0,0 +1,187 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . + */ +class HtmlGovernmentFailedCommandResolver extends BaseCommandResolver implements CommandResolver { + /** + * Last successfull resolved command + */ + private $lastCommandInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to "Html" + $this->setCommandPrefix('Html'); + } + + /** + * Creates an instance of a Html command resolver with a given default 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 default command is not set + * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable + */ + public static final function createHtmlGovernmentFailedCommandResolver ($commandName, ManageableApplication $appInstance) { + // Create the new instance + $resolverInstance = new HtmlGovernmentFailedCommandResolver(); + + // Get request instance + $requestInstance = $appInstance->getRequestInstance(); + + // 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->resolveCommandByRequest($requestInstance) instanceof Commandable) { + // Invalid command found (missing interface?) + throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); + } + + // 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 + * it was not found + * + * @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 resolveCommandByRequest (Requestable $requestInstance) { + // Init instance + $commandInstance = null; + + // This goes fine so let's resolv the command + $commandName = $requestInstance->getRequestElement('page'); + + // Is there a "failed" request? + if ($requestInstance->isRequestElementSet('failed')) { + // Then include with within the command name + $commandName = sprintf('%s_%s', $commandName, $requestInstance->getRequestElement('failed')); + } // END - if + + // Is the command empty? Then fall back to default command + if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command'); + + // 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); + + // 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->lastCommandInstance = $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_web_command'); + + // Check if command is valid + if ($this->isCommandValid($commandName) === false) { + // This command is invalid! + throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); + } + + // Get the command + $commandInstance = $this->loadCommand($commandName); + + // Return the 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()->getConfigEntry('default_web_command'); + + // Init command instance + $commandInstance = null; + + // Create command class name + $this->setClassName(sprintf('%s%sCommand', + $this->getCommandPrefix(), + $this->convertToClassName($commandName) + )); + + // Is this class loaded? + 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($this->getClassName(), array($this)); + + // Return the result + return $commandInstance; + } +} + +// [EOF] +?> diff --git a/application/shipsimu/main/resolver/controller/.htaccess b/application/shipsimu/main/resolver/controller/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/shipsimu/main/resolver/controller/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/shipsimu/main/resolver/controller/html/.htaccess b/application/shipsimu/main/resolver/controller/html/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/application/shipsimu/main/resolver/controller/html/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/application/shipsimu/main/resolver/controller/html/class_ShipSimuHtmlControllerResolver.php b/application/shipsimu/main/resolver/controller/html/class_ShipSimuHtmlControllerResolver.php new file mode 100644 index 0000000..9f18f22 --- /dev/null +++ b/application/shipsimu/main/resolver/controller/html/class_ShipSimuHtmlControllerResolver.php @@ -0,0 +1,104 @@ + + * @version 0.0.0 + * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2015 Ship-Simu 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 . + */ +class ShipSimuHtmlControllerResolver extends BaseControllerResolver implements ControllerResolver { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set prefix to 'ShipSimuHtml' + $this->setClassPrefix('ShipSimuHtml'); + } + + /** + * Creates an instance of a resolver class with a given command + * + * @param $controllerName The controller we shall resolve + * @param $applicationInstance An instance of a manageable application helper class + * @return $resolverInstance The prepared controller resolver instance + * @throws EmptyVariableException Thrown if default command is not set + * @throws InvalidControllerException Thrown if default controller is invalid + */ + public static final function createShipSimuHtmlControllerResolver ($controllerName, ManageableApplication $applicationInstance) { + // Create the new instance + $resolverInstance = new ShipSimuHtmlControllerResolver(); + + // Is the variable $controllerName set and the command is valid? + if (empty($controllerName)) { + // Then thrown an exception here + throw new EmptyVariableException(array($resolverInstance, 'commandName'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); + } elseif ($resolverInstance->isControllerValid($controllerName) === FALSE) { + // Invalid command found + throw new InvalidControllerException(array($resolverInstance, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } + + // Set the application instance + $resolverInstance->setApplicationInstance($applicationInstance); + + // Set command name + $resolverInstance->setControllerName($controllerName); + + // Return the prepared instance + return $resolverInstance; + } + + /** + * Resolves the default controller of the given command + * + * @return $controllerInstance A controller instance for the default + * command + * @throws InvalidControllerInstanceException Thrown if $controllerInstance + * is invalid + */ + public function resolveController () { + // Init variables + $controllerName = ''; + $controllerInstance = NULL; + + // Get the command name + $controllerName = $this->getControllerName(); + + // Get the command + $controllerInstance = $this->loadController($controllerName); + + // And validate it + if ((!is_object($controllerInstance)) || (!$controllerInstance instanceof Controller)) { + // This command has an invalid instance! + throw new InvalidControllerInstanceException(array($this, $controllerName), self::EXCEPTION_INVALID_CONTROLLER); + } // END - if + + // Set last controller + $this->setResolvedInstance($controllerInstance); + + // Return the maybe resolved instance + return $controllerInstance; + } +} + +// [EOF] +?> diff --git a/application/shipsimu/main/resolver/web/.htaccess b/application/shipsimu/main/resolver/web/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/application/shipsimu/main/resolver/web/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/application/shipsimu/main/resolver/web/class_WebCompanyCommandResolver.php b/application/shipsimu/main/resolver/web/class_WebCompanyCommandResolver.php deleted file mode 100644 index e5fcfb4..0000000 --- a/application/shipsimu/main/resolver/web/class_WebCompanyCommandResolver.php +++ /dev/null @@ -1,190 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . - */ -class WebCompanyCommandResolver extends BaseCommandResolver implements CommandResolver { - /** - * Last successfull resolved command - */ - private $lastCommandInstance = null; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set prefix to "Web" - $this->setCommandPrefix('Web'); - } - - /** - * Creates an instance of a Web command resolver with a given default 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 default command is not set - * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable - */ - public static final function createWebCompanyCommandResolver ($commandName, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new WebCompanyCommandResolver(); - - // Get request instance - $requestInstance = $appInstance->getRequestInstance(); - - // 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->resolveCommandByRequest($requestInstance) instanceof Commandable) { - // Invalid command found (missing interface?) - throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); - } - - // 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 - * it was not found - * - * @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 resolveCommandByRequest (Requestable $requestInstance) { - // Init instance - $commandInstance = null; - - // This goes fine so let's resolv the command - $commandName = str_replace('-', '_', $requestInstance->getRequestElement('app')) . '_' . $requestInstance->getRequestElement('page'); - - // Is there a "failed" request? - if ($requestInstance->isRequestElementSet('failed')) { - // Then include with within the command name - $commandName = $commandName . '_' . $requestInstance->getRequestElement('failed'); - } // END - if - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command'); - - // 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); - - // 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->lastCommandInstance = $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_web_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === false) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // Return the 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()->getConfigEntry('default_web_command'); - - // Init command instance - $commandInstance = null; - - // Get 'app' from the application - $app = Registry::getRegistry()->getInstance('application')->getRequestInstance()->getRequestElement('app'); - - // Create command class name - $this->setClassName(sprintf("%s%sCommand", - $this->getCommandPrefix(), - $this->convertToClassName($commandName) - )); - - // Is this class loaded? - 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($this->getClassName(), array($this)); - - // Return the result - return $commandInstance; - } -} - -// [EOF] -?> diff --git a/application/shipsimu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php b/application/shipsimu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php deleted file mode 100644 index 9456c08..0000000 --- a/application/shipsimu/main/resolver/web/class_WebGovernmentFailedCommandResolver.php +++ /dev/null @@ -1,187 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 Ship-Simu 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 . - */ -class WebGovernmentFailedCommandResolver extends BaseCommandResolver implements CommandResolver { - /** - * Last successfull resolved command - */ - private $lastCommandInstance = null; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set prefix to "Web" - $this->setCommandPrefix('Web'); - } - - /** - * Creates an instance of a Web command resolver with a given default 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 default command is not set - * @throws InvalidInterfaceException Thrown if command does not implement interface Commandable - */ - public static final function createWebGovernmentFailedCommandResolver ($commandName, ManageableApplication $appInstance) { - // Create the new instance - $resolverInstance = new WebGovernmentFailedCommandResolver(); - - // Get request instance - $requestInstance = $appInstance->getRequestInstance(); - - // 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->resolveCommandByRequest($requestInstance) instanceof Commandable) { - // Invalid command found (missing interface?) - throw new InvalidInterfaceException(array($userInstance, 'ManageableMember'), self::EXCEPTION_REQUIRED_INTERFACE_MISSING); - } - - // 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 - * it was not found - * - * @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 resolveCommandByRequest (Requestable $requestInstance) { - // Init instance - $commandInstance = null; - - // This goes fine so let's resolv the command - $commandName = $requestInstance->getRequestElement('page'); - - // Is there a "failed" request? - if ($requestInstance->isRequestElementSet('failed')) { - // Then include with within the command name - $commandName = sprintf("%s_%s", $commandName, $requestInstance->getRequestElement('failed')); - } // END - if - - // Is the command empty? Then fall back to default command - if (empty($commandName)) $commandName = $this->getConfigInstance()->getConfigEntry('default_web_command'); - - // 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); - - // 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->lastCommandInstance = $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_web_command'); - - // Check if command is valid - if ($this->isCommandValid($commandName) === false) { - // This command is invalid! - throw new InvalidCommandException(array($this, $commandName), self::EXCEPTION_INVALID_COMMAND); - } - - // Get the command - $commandInstance = $this->loadCommand($commandName); - - // Return the 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()->getConfigEntry('default_web_command'); - - // Init command instance - $commandInstance = null; - - // Create command class name - $this->setClassName(sprintf("%s%sCommand", - $this->getCommandPrefix(), - $this->convertToClassName($commandName) - )); - - // Is this class loaded? - 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($this->getClassName(), array($this)); - - // Return the result - return $commandInstance; - } -} - -// [EOF] -?>