From: Roland Häder Date: Fri, 14 Nov 2008 21:39:09 +0000 (+0000) Subject: A performed action now always requires an action class X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=ddac7be24465ecb1d885b3686a3037f10e2aec46 A performed action now always requires an action class --- diff --git a/.gitattributes b/.gitattributes index 57f3ab7..b9367f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -165,7 +165,9 @@ application/ship-simu/main/actions/ship-simu/class_ShipSimuProfileAction.php -te application/ship-simu/main/actions/web/.htaccess -text application/ship-simu/main/actions/web/class_WebShipSimuLogin -text application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php -text +application/ship-simu/main/actions/web/class_WebShipSimuLoginLogoutAction.php -text application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php -text +application/ship-simu/main/actions/web/class_WebShipSimuLoginWelcomeAction.php -text application/ship-simu/main/bank/.htaccess -text application/ship-simu/main/bank/class_MoneyBank.php -text application/ship-simu/main/class_ -text diff --git a/application/ship-simu/main/actions/web/class_WebShipSimuLogin b/application/ship-simu/main/actions/web/class_WebShipSimuLogin index f6cb95e..99b2e56 100644 --- a/application/ship-simu/main/actions/web/class_WebShipSimuLogin +++ b/application/ship-simu/main/actions/web/class_WebShipSimuLogin @@ -55,7 +55,7 @@ class WebShipSimuLogin???Action extends BaseAction implements Commandable, Regis * @param $requestInstance An instance of a class with an Requestable interface * @param $responseInstance An instance of a class with an Responseable interface * @return void - * @todo Maybe add fetching company list of current user here? + * @todo 0% done */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Unfinished method @@ -67,10 +67,10 @@ class WebShipSimuLogin???Action extends BaseAction implements Commandable, Regis * @param $controllerInstance A controller instance * @param $requestInstance An instance of a class with an Requestable interface * @return void + * @todo Add some filters here */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Add user status filter here - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter')); + // Unfinished method } } diff --git a/application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php b/application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php index e416055..e4c3ed9 100644 --- a/application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php +++ b/application/ship-simu/main/actions/web/class_WebShipSimuLoginCompanyAction.php @@ -67,10 +67,10 @@ class WebShipSimuLoginCompanyAction extends BaseAction implements Commandable, R * @param $controllerInstance A controller instance * @param $requestInstance An instance of a class with an Requestable interface * @return void + * @todo Add some filters here */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Add user status filter here - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter')); + // Unfinished method } } diff --git a/application/ship-simu/main/actions/web/class_WebShipSimuLoginLogoutAction.php b/application/ship-simu/main/actions/web/class_WebShipSimuLoginLogoutAction.php new file mode 100644 index 0000000..fed0d1d --- /dev/null +++ b/application/ship-simu/main/actions/web/class_WebShipSimuLoginLogoutAction.php @@ -0,0 +1,76 @@ + + * @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 WebShipSimuLoginLogoutAction extends BaseAction implements Commandable, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this action + * + * @param $resolverInstance An instance of an action resolver + * @return $actionInstance An instance of this action class + */ + public final static function createWebShipSimuLoginLogoutAction (ActionResolver $resolverInstance) { + // Get a new instance + $actionInstance = new WebShipSimuLoginLogoutAction(); + + // Set the resolver instance + $actionInstance->setResolverInstance($resolverInstance); + + // Return the instance + return $actionInstance; + } + + /** + * Executes the command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Unfinished method + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + } +} + +// [EOF] +?> diff --git a/application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php b/application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php index fc25b95..8d02747 100644 --- a/application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php +++ b/application/ship-simu/main/actions/web/class_WebShipSimuLoginRefillAction.php @@ -69,9 +69,6 @@ class WebShipSimuLoginRefillAction extends BaseAction implements Commandable, Re * @return void */ public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { - // Add user status filter here - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter')); - // Is the refill page active? $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('refill_page_filter')); diff --git a/application/ship-simu/main/actions/web/class_WebShipSimuLoginWelcomeAction.php b/application/ship-simu/main/actions/web/class_WebShipSimuLoginWelcomeAction.php new file mode 100644 index 0000000..64f60b9 --- /dev/null +++ b/application/ship-simu/main/actions/web/class_WebShipSimuLoginWelcomeAction.php @@ -0,0 +1,78 @@ + + * @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 WebShipSimuLoginWelcomeAction extends BaseAction implements Commandable, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + } + + /** + * Creates an instance of this action + * + * @param $resolverInstance An instance of an action resolver + * @return $actionInstance An instance of this action class + */ + public final static function createWebShipSimuLoginWelcomeAction (ActionResolver $resolverInstance) { + // Get a new instance + $actionInstance = new WebShipSimuLoginWelcomeAction(); + + // Set the resolver instance + $actionInstance->setResolverInstance($resolverInstance); + + // Return the instance + return $actionInstance; + } + + /** + * Executes the command with given request and response objects + * + * @param $requestInstance An instance of a class with an Requestable interface + * @param $responseInstance An instance of a class with an Responseable interface + * @return void + * @todo 0% done + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Unfinished method + } + + /** + * Adds extra filters to the given controller instance + * + * @param $controllerInstance A controller instance + * @param $requestInstance An instance of a class with an Requestable interface + * @return void + * @todo Add some filters here + */ + public function addExtraFilters (Controller $controllerInstance, Requestable $requestInstance) { + // Unfinished method + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/actions/class_InvalidActionException.php b/inc/classes/exceptions/actions/class_InvalidActionException.php index addebdb..96c1b73 100644 --- a/inc/classes/exceptions/actions/class_InvalidActionException.php +++ b/inc/classes/exceptions/actions/class_InvalidActionException.php @@ -31,10 +31,11 @@ class InvalidActionException extends FrameworkException { */ public function __construct(array $msgArray, $code) { // Prepare the message - $message = sprintf("[%s:%d] Cannot resolve action %s.", + $message = sprintf("[%s:%d] Cannot resolve action %s (%s).", $msgArray[0]->__toString(), $this->getLine(), - $msgArray[1] + $msgArray[1], + $msgArray[0]->getClassName() ); // Call parent contructor with message diff --git a/inc/classes/exceptions/class_FrameworkException.php b/inc/classes/exceptions/class_FrameworkException.php index 267744c..31a7ba6 100644 --- a/inc/classes/exceptions/class_FrameworkException.php +++ b/inc/classes/exceptions/class_FrameworkException.php @@ -61,9 +61,18 @@ abstract class FrameworkException extends ReflectionException { // End here exit; } // END - if - // Make sure everything is assigned properly parent::__construct($message, $code); + + // Log it away if DEBUG_ALL is set + if (defined('DEBUG_ALL')) { + // Log the error + error_log(sprintf("[%s:] %s (%s)", + $this->__toString(), + $message, + $this->getHexCode() + )); + } // END - if } /** diff --git a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php index 3149a25..98f76cd 100644 --- a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php @@ -142,7 +142,7 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { } /** - * Adds extra filters to the given controller instance + * Adds extra filters to the given controller instance. An corresponding action class must now exist! * * @param $controllerInstance A controller instance * @param $requestInstance An instance of a class with an Requestable interface @@ -179,22 +179,17 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { // Get application instance $applicationInstance = $this->getResolverInstance()->getApplicationInstance(); - // Try to get an action resolver for the given action - try { - // Get a resolver - $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance); + // Get a resolver + $actionResolver = WebActionResolver::createWebActionResolver($this->actionName, $applicationInstance); - // Resolve the action - $actionInstance = $actionResolver->resolveAction(); + // Resolve the action + $actionInstance = $actionResolver->resolveAction(); - // Add more action-specific filters - $actionInstance->addExtraFilters($controllerInstance, $requestInstance); + // Add more action-specific filters + $actionInstance->addExtraFilters($controllerInstance, $requestInstance); - // Remember this action in registry - Registry::getRegistry()->addInstance('action', $actionInstance); - } catch (InvalidActionException $e) { - // Silently ignored because no special action was found - } + // Remember this action in registry + Registry::getRegistry()->addInstance('action', $actionInstance); } } diff --git a/inc/classes/main/controller/web/class_WebLoginController.php b/inc/classes/main/controller/web/class_WebLoginController.php index f4ce053..83964d2 100644 --- a/inc/classes/main/controller/web/class_WebLoginController.php +++ b/inc/classes/main/controller/web/class_WebLoginController.php @@ -47,6 +47,12 @@ class WebLoginController extends BaseController implements Controller { // Set the command resolver $controllerInstance->setResolverInstance($resolverInstance); + // Add user auth filter (we don't need an update of the user here because it will be redirected) + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_filter')); + + // Check for user status by default + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_status_filter')); + // Return the prepared instance return $controllerInstance; } diff --git a/inc/classes/main/resolver/action/class_BaseActionResolver.php b/inc/classes/main/resolver/action/class_BaseActionResolver.php index 9e92771..250fa01 100644 --- a/inc/classes/main/resolver/action/class_BaseActionResolver.php +++ b/inc/classes/main/resolver/action/class_BaseActionResolver.php @@ -112,8 +112,6 @@ class BaseActionResolver extends BaseResolver { * "Loads" current action and instances it if not yet cached * * @return $actionInstance A loaded action instance - * @throws InvalidActionException Thrown if even the default - * action class is missing (bad!) */ protected function loadAction () { // Init action instance