From 792542694524c78ffc47fb8c18ab9615f98c76ca Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 27 May 2008 17:25:33 +0000 Subject: [PATCH] Intercepting filter basicly added, generic form processor implemented (unfinished), small fixes --- .gitattributes | 13 ++- .../ship-simu/class_ApplicationHelper.php | 14 ++- .../ship-simu/templates/de/code/register.ctp | 32 +++---- .../interfaces/commands/class_Commandable.php | 2 +- .../filter}/.htaccess | 0 .../interfaces/filter/class_Filterable.php | 36 ++++++++ .../main/class_BaseFrameworkSystem.php | 34 ++++++- .../commands/web/class_WebDoFormCommand.php | 74 +++++++++++++++ .../main/controller/class_BaseController.php | 84 +++++++++++++++++ .../default/class_WebDefaultController.php | 20 +--- .../class_WebDefaultNewsController.php | 20 +--- inc/classes/main/controller/form/.htaccess | 1 + .../class_WebDoFormController.php} | 35 ++++--- inc/classes/main/filter/.htaccess | 1 + inc/classes/main/filter/class_ | 72 +++++++++++++++ .../filter/class_AbstractFilterDecorator.php | 87 ++++++++++++++++++ inc/classes/main/filter/class_FilterChain.php | 92 +++++++++++++++++++ inc/classes/main/filter/validator/.htaccess | 1 + .../class_UserNameValidatorFilter.php | 75 +++++++++++++++ .../main/helper/web/class_WebFormHelper.php | 22 +++-- .../main/resolver/class_BaseResolver.php | 9 +- .../resolver/web/class_WebCommandResolver.php | 14 +-- .../web/class_WebControllerResolver.php | 22 ++++- 23 files changed, 662 insertions(+), 98 deletions(-) rename inc/classes/{main/controller/registration => interfaces/filter}/.htaccess (100%) create mode 100644 inc/classes/interfaces/filter/class_Filterable.php create mode 100644 inc/classes/main/commands/web/class_WebDoFormCommand.php create mode 100644 inc/classes/main/controller/form/.htaccess rename inc/classes/main/controller/{registration/class_DefaultRegistrationController.php => form/class_WebDoFormController.php} (63%) create mode 100644 inc/classes/main/filter/.htaccess create mode 100644 inc/classes/main/filter/class_ create mode 100644 inc/classes/main/filter/class_AbstractFilterDecorator.php create mode 100644 inc/classes/main/filter/class_FilterChain.php create mode 100644 inc/classes/main/filter/validator/.htaccess create mode 100644 inc/classes/main/filter/validator/class_UserNameValidatorFilter.php diff --git a/.gitattributes b/.gitattributes index afa5c07..8c469f2 100644 --- a/.gitattributes +++ b/.gitattributes @@ -228,6 +228,8 @@ inc/classes/interfaces/debug/.htaccess -text inc/classes/interfaces/debug/class_Debugger.php -text inc/classes/interfaces/extended/.htaccess -text inc/classes/interfaces/extended/class_LimitableObject.php -text +inc/classes/interfaces/filter/.htaccess -text +inc/classes/interfaces/filter/class_Filterable.php -text inc/classes/interfaces/io/.htaccess -text inc/classes/interfaces/io/class_Streamable.php -text inc/classes/interfaces/io/file/.htaccess -text @@ -255,6 +257,7 @@ inc/classes/main/commands/.htaccess -text inc/classes/main/commands/class_ -text inc/classes/main/commands/class_BaseCommand.php -text inc/classes/main/commands/web/.htaccess -text +inc/classes/main/commands/web/class_WebDoFormCommand.php -text inc/classes/main/commands/web/class_WebHomeCommand.php -text inc/classes/main/commands/web/class_WebRegisterCommand.php -text inc/classes/main/compressor/.htaccess -text @@ -269,8 +272,8 @@ inc/classes/main/controller/class_BaseController.php -text inc/classes/main/controller/default/.htaccess -text inc/classes/main/controller/default/class_WebDefaultController.php -text inc/classes/main/controller/default/class_WebDefaultNewsController.php -text -inc/classes/main/controller/registration/.htaccess -text -inc/classes/main/controller/registration/class_DefaultRegistrationController.php -text +inc/classes/main/controller/form/.htaccess -text +inc/classes/main/controller/form/class_WebDoFormController.php -text inc/classes/main/database/.htaccess -text inc/classes/main/database/class_BaseDatabaseFrontend.php -text inc/classes/main/database/classes/.htaccess -text @@ -288,6 +291,12 @@ inc/classes/main/factories/objects/.htaccess -text inc/classes/main/factories/objects/class_ObjectFactory.php -text inc/classes/main/factories/web/.htaccess -text inc/classes/main/factories/web/class_NewsFactory.php -text +inc/classes/main/filter/.htaccess -text +inc/classes/main/filter/class_ -text +inc/classes/main/filter/class_AbstractFilterDecorator.php -text +inc/classes/main/filter/class_FilterChain.php -text +inc/classes/main/filter/validator/.htaccess -text +inc/classes/main/filter/validator/class_UserNameValidatorFilter.php -text inc/classes/main/helper/.htaccess -text inc/classes/main/helper/class_ -text inc/classes/main/helper/class_BaseHelper.php -text diff --git a/application/ship-simu/class_ApplicationHelper.php b/application/ship-simu/class_ApplicationHelper.php index 7537386..b5ad8ee 100644 --- a/application/ship-simu/class_ApplicationHelper.php +++ b/application/ship-simu/class_ApplicationHelper.php @@ -183,11 +183,19 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // ... and a new response object $responseInstance = HttpResponse::createHttpResponse($this); - // Get default command - $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); + // Get command parameter + $commandPara = $this->getConfigInstance()->readConfig("command_parameter"); + + // Get the parameter from the request + $commandName = $requestInstance->getRequestElement($commandPara); + + // If it is null then get default command + if (is_null($commandName)) { + $commandName = $this->getConfigInstance()->readConfig("default_command"); + } // Get a resolver - $resolverInstance = WebControllerResolver::createWebControllerResolver($defaultCommand, $this); + $resolverInstance = WebControllerResolver::createWebControllerResolver($commandName, $this); // Get a new controller instance as well $controllerInstance = $resolverInstance->resolveDefaultController(); diff --git a/application/ship-simu/templates/de/code/register.ctp b/application/ship-simu/templates/de/code/register.ctp index adc4561..4511dfc 100644 --- a/application/ship-simu/templates/de/code/register.ctp +++ b/application/ship-simu/templates/de/code/register.ctp @@ -9,19 +9,19 @@ $helper = WebFormHelper::createWebFormHelper($this, "shipsimu_register"); $helper->addFormGroup("login", "Bitte gebe hier gewünschten Nickname und dein Zugangspasswort ein."); $helper->addFormSubGroup("username", "Dein Nickname wird erst nach Absenden des Formulares geprüft. Später bauen wir dann einen automatischen Test ein, der dir sofort zeigt, ob der Nickname bereits vergeben ist."); $helper->addFieldText("username", "Nickname im Spiel:"); -$helper->addInputTextField("username", 10, 255); +$helper->addInputTextField("username"); $helper->addFormSubGroup("password", "Dein Passwort sollte nicht zu leicht erratbar sein. Später bauen wir hier noch einen automatischen Test ein, der dir sofort die Passwortstärke anzeigt."); $helper->addFieldText("pass1", "Passwort:"); -$helper->addInputPasswordField("pass1", 5, 255); +$helper->addInputPasswordField("pass1"); $helper->addFieldText("pass2", "Passwortwiederholung:"); -$helper->addInputPasswordField("pass2", 5, 255); +$helper->addInputPasswordField("pass2"); if ($helper->ifRegisterRequiresEmailVerification()) { $helper->addFormGroup("email", "Bitte gebe deine Email zweimal (ein zweites Mal zur Bestätigung) ein, damit wir dir deinen Freischaltlink zusenden können."); $helper->addFieldText("email1", "Email-Adresse:"); - $helper->addInputTextField("email1", 15, 255); + $helper->addInputTextField("email1"); $helper->addFieldText("email2", "Wiederholung Email-Adresse:"); - $helper->addInputTextField("email2", 15, 255); + $helper->addInputTextField("email2"); } // END - email verification if ($helper->ifRegisterIncludesProfile()) { @@ -29,46 +29,46 @@ if ($helper->ifRegisterIncludesProfile()) { if (!$helper->ifRegisterRequiresEmailVerification()) { $helper->addFormSubGroup("email", "Die Angabe deiner Email-Adresse ist nur dann nötig, wenn du auch Email-Benachrichtigungen (*1) haben möchtest."); $helper->addFieldText("email1", "Email-Adresse:"); - $helper->addInputTextField("email1", 15, 255); + $helper->addInputTextField("email1"); } // END - No email verification // Persoenliche Daten mit in der Anmeldung abfragen? if ($helper->ifRegisterIncludesPersonaData()) { $helper->addFormSubGroup("persona", "Wenn du magst, dann vervollständige deine komplette Adresse mit deinem Namen."); $helper->addFieldText("surname", "Dein Vorname:"); - $helper->addInputTextField("surname", 10, 255); + $helper->addInputTextField("surname"); $helper->addFieldText("family", "Dein Nachname:"); - $helper->addInputTextField("family", 10, 255); + $helper->addInputTextField("family"); $helper->addFieldText("street", "Strasse und Hausnummer:"); - $helper->addInputTextField("street", 10, 255); + $helper->addInputTextField("street"); $helper->addFieldText("city", "Wohnort:"); - $helper->addInputTextField("city", 10, 255); + $helper->addInputTextField("city"); } // END - Persona data $helper->addFormSubGroup("zip", "Magst du uns auch deine Postleitzahl verraten?"); $helper->addFieldText("zip", "Postleitzahl:"); - $helper->addInputTextField("zip", 10, 255); + $helper->addInputTextField("zip"); $helper->addFormSubGroup("chat", "Gebe hier deine Nicknames bzw. Nummern an:"); if ($helper->ifChatEnabled("icq")) { $helper->addFieldText("icq", "ICQ-Nummer:"); - $helper->addInputTextField("icq", 10, 15); + $helper->addInputTextField("icq"); } if ($helper->ifChatEnabled("jabber")) { $helper->addFieldText("jabber", "Jabber:"); - $helper->addInputTextField("jabber", 15, 50); + $helper->addInputTextField("jabber"); } if ($helper->ifChatEnabled("yahoo")) { $helper->addFieldText("yahoo", "Yahoo!:"); - $helper->addInputTextField("yahoo", 15, 50); + $helper->addInputTextField("yahoo"); } if ($helper->ifChatEnabled("aol")) { $helper->addFieldText("aol", "AOL-Screenname:"); - $helper->addInputTextField("aol", 15, 50); + $helper->addInputTextField("aol"); } if ($helper->ifChatEnabled("msn")) { $helper->addFieldText("msn", "MSN:"); - $helper->addInputTextField("msn", 15, 50); + $helper->addInputTextField("msn"); } if (!$helper->ifRegisterRequiresEmailVerification()) { diff --git a/inc/classes/interfaces/commands/class_Commandable.php b/inc/classes/interfaces/commands/class_Commandable.php index 4b3eaba..8b3392d 100644 --- a/inc/classes/interfaces/commands/class_Commandable.php +++ b/inc/classes/interfaces/commands/class_Commandable.php @@ -23,7 +23,7 @@ */ interface Commandable extends FrameworkInterface { /** - * Executes the given command with given request and response objects + * 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 diff --git a/inc/classes/main/controller/registration/.htaccess b/inc/classes/interfaces/filter/.htaccess similarity index 100% rename from inc/classes/main/controller/registration/.htaccess rename to inc/classes/interfaces/filter/.htaccess diff --git a/inc/classes/interfaces/filter/class_Filterable.php b/inc/classes/interfaces/filter/class_Filterable.php new file mode 100644 index 0000000..bc4bb30 --- /dev/null +++ b/inc/classes/interfaces/filter/class_Filterable.php @@ -0,0 +1,36 @@ + + * @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 . + */ +interface Filterable extends FrameworkInterface { + /** + * Executes the filter 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 + */ + function execute (Requestable $requestInstance, Responseable $responseInstance); +} + +// +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index f460986..0db6d28 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -905,9 +905,10 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { /** * Output a partial stub message for the caller method * + * @param $message An optional message to display * @return void */ - protected function partialStub () { + protected function partialStub ($message = "") { // Get the backtrace $backtrace = debug_backtrace(); @@ -917,16 +918,39 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $methodName = $backtrace[1]['class']."::".$backtrace[1]['function']; } + // Construct the full message + $stubMessage = sprintf("[%s:] Partial stub!", + $methodName + ); + + // Is the extra message given? + if (!empty($message)) { + // Then add it as well + $stubMessage .= sprintf(" Message: %s", $message); + } + // Debug instance is there? if (!is_null($this->getDebugInstance())) { // Output stub message - $this->getDebugInstance()->output(sprintf("[%s:] Partial stub!
\n", - $methodName - )); + $this->getDebugInstance()->output($stubMessage); } else { // Trigger an error - trigger_error(sprintf("[%s:] Partial stub!", $methodName)); + trigger_error($stubMessage."
\n"); + } + } + + /** + * Converts e.g. a command from URL to a valid class by keeping out bad characters + * + * @param $str The string, what ever it is needs to be converted + * @return $className Generated class name + */ + public function convertToClassName ($str) { + $className = ""; + foreach (explode("_", $str) as $strPart) { + $className .= ucfirst(strtolower($strPart)); } + return $className; } } diff --git a/inc/classes/main/commands/web/class_WebDoFormCommand.php b/inc/classes/main/commands/web/class_WebDoFormCommand.php new file mode 100644 index 0000000..1b41b49 --- /dev/null +++ b/inc/classes/main/commands/web/class_WebDoFormCommand.php @@ -0,0 +1,74 @@ + + * @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 WebDoFormCommand extends BaseCommand implements Commandable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set special description + $this->setObjectDescription("Home-Command"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $commandInstance An instance a prepared command class + */ + public final static function createWebDoFormCommand (CommandResolver $resolverInstance) { + // Get new instance + $commandInstance = new WebDoFormCommand(); + + // Set the application instance + $commandInstance->setResolverInstance($resolverInstance); + + // Return the prepared instance + return $commandInstance; + } + + /** + * Executes the given 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + die(__METHOD__.": Stub!"); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index f7aea5c..607e042 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -22,6 +22,21 @@ * along with this program. If not, see . */ class BaseController extends BaseFrameworkSystem { + /** + * Instance of a CommandResolver class + */ + private $resolverInstance = null; + + /** + * Pre filter chain instance + */ + private $preFilterChain = null; + + /** + * Post filter chain instance + */ + private $postFilterChain = null; + /** * Protected constructor * @@ -33,6 +48,75 @@ class BaseController extends BaseFrameworkSystem { // Clean up a little $this->removeNumberFormaters(); + $this->removeSystemArray(); + + // Initialize both filter chains + $this->preFilterChain = FilterChain::createFilterChain(); + $this->postFilterChain = FilterChain::createFilterChain(); + } + + /** + * Getter for a command resolver instance + * + * @ + * @return $resolverInstance An instance of a command resolver class + */ + public final function getResolverInstance () { + return $this->resolverInstance; + } + + /** + * Setter for a command resolver instance + * + * @param $resolverInstance An instance of a command resolver class + * @return void + */ + public final function setResolverInstance (CommandResolver $resolverInstance) { + $this->resolverInstance = $resolverInstance; + } + + /** + * Adds a filter to the pre filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPreFilter (Filterable $filterInstance) { + // Add the pre filter + $this->preFilterChain->addFilter($filterInstance); + } + + /** + * Adds a filter to the post filter chain + * + * @param $filterInstance An instance of a filter + * @return void + */ + public function addPostFilter (Filterable $filterInstance) { + // Add the post filter + $this->postFilterChain->addFilter($filterInstance); + } + + /** + * Executes all pre filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePreFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->preFilterChain->processFilters($requestInstance, $responseInstance); + } + + /** + * Executes all post filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + protected function executePostFilters (Requestable $requestInstance, Responseable $responseInstance) { + $this->postFilterChain->processFilters($requestInstance, $responseInstance); } } diff --git a/inc/classes/main/controller/default/class_WebDefaultController.php b/inc/classes/main/controller/default/class_WebDefaultController.php index 9830891..d16713e 100644 --- a/inc/classes/main/controller/default/class_WebDefaultController.php +++ b/inc/classes/main/controller/default/class_WebDefaultController.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class WebWebDefaultController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - /** * Protected constructor * @@ -41,9 +36,6 @@ class WebWebDefaultController extends BaseController implements Controller { // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebWebDefaultController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,7 +64,7 @@ class WebWebDefaultController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); // Execute the command $commandInstance->execute($requestInstance, $responseInstance); diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index ea690a9..a6e2ebc 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -22,11 +22,6 @@ * along with this program. If not, see . */ class WebDefaultNewsController extends BaseController implements Controller { - /** - * Instance of a CommandResolver class - */ - private $resolverInstance = null; - /** * Protected constructor * @@ -41,9 +36,6 @@ class WebDefaultNewsController extends BaseController implements Controller { // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** @@ -63,16 +55,6 @@ class WebDefaultNewsController extends BaseController implements Controller { return $controllerInstance; } - /** - * Setter for a command resolver instance - * - * @param $resolverInstance An instance of a command resolver class - * @return void - */ - public final function setResolverInstance (CommandResolver $resolverInstance) { - $this->resolverInstance = $resolverInstance; - } - /** * Handles the given request and response * @@ -82,7 +64,7 @@ class WebDefaultNewsController extends BaseController implements Controller { */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { // Get the command instance from the resolver by sending a request instance to the resolver - $commandInstance = $this->resolverInstance->resolvCommandByRequest($requestInstance); + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); // Load the news here $this->loadNewsByRequest($requestInstance); diff --git a/inc/classes/main/controller/form/.htaccess b/inc/classes/main/controller/form/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/controller/form/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/registration/class_DefaultRegistrationController.php b/inc/classes/main/controller/form/class_WebDoFormController.php similarity index 63% rename from inc/classes/main/controller/registration/class_DefaultRegistrationController.php rename to inc/classes/main/controller/form/class_WebDoFormController.php index 24d7040..7e2e086 100644 --- a/inc/classes/main/controller/registration/class_DefaultRegistrationController.php +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -1,7 +1,6 @@ * @version 0.0.0 @@ -22,9 +21,9 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class DefaultRegistrationController extends BaseController implements Controller { +class WebDoFormController extends BaseController implements Controller { /** - * Protected constructor + * Private constructor * * @return void */ @@ -33,23 +32,24 @@ class DefaultRegistrationController extends BaseController implements Controller parent::__construct(__CLASS__); // Set part description - $this->setObjectDescription("Ein Standart-Anmelde-Controller"); + $this->setObjectDescription("Controller for handling forms"); // Create unique ID number $this->createUniqueID(); - - // Clean up a little - $this->removeSystemArray(); } /** * Creates an instance of this class * + * @param $resolverInstance An instance of a resolver class * @return $controllerInstance A prepared instance of this class */ - public final static function createDefaultRegistrationController () { + public final static function createWebDoFormController (CommandResolver $resolverInstance) { // Create the instance - $controllerInstance = new DefaultRegistrationController(); + $controllerInstance = new WebDoFormController(); + + // Set resolver instance + $controllerInstance->setResolverInstance($resolverInstance); // Return the prepared instance return $controllerInstance; @@ -63,7 +63,20 @@ class DefaultRegistrationController extends BaseController implements Controller * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { - die(__METHOD__.": Stub!"); + // Run all pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // Get command instance from resolver + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + + // Execute the command + $commandInstance->execute($requestInstance, $responseInstance); + + // Run all post filters + $this->executePostFilters($requestInstance, $responseInstance); + + // Do something more here + die("OK"); } } diff --git a/inc/classes/main/filter/.htaccess b/inc/classes/main/filter/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/class_ b/inc/classes/main/filter/class_ new file mode 100644 index 0000000..b79b83d --- /dev/null +++ b/inc/classes/main/filter/class_ @@ -0,0 +1,72 @@ + + * @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 ???Filter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A concrete filter"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function create???Filter () { + // Get a new instance + $filterInstance = new ???Filter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub("Please implement this method."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_AbstractFilterDecorator.php b/inc/classes/main/filter/class_AbstractFilterDecorator.php new file mode 100644 index 0000000..a9a1d4a --- /dev/null +++ b/inc/classes/main/filter/class_AbstractFilterDecorator.php @@ -0,0 +1,87 @@ + + * @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 . + */ +abstract class AbstractFilterDecorator extends BaseFrameworkSystem implements Filterable { + /** + * The decorated filter instance + */ + private $filterInstance = null; + + /** + * Private constructor + * + * @param $className Name of the real class' name + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Setter for the decorated filter instance + * + * @param $filterInstance An instance of a filter + * @return void + */ + protected final function setFilterInstance (Filterable $filterInstance) { + $this->filterInstance = $filterInstance; + } + + /** + * Getter for the decorated filter instance + * + * @return $filterInstance An instance of a filter + */ + protected final function getFilterInstance () { + return $this->filterInstance; + } + + /** + * Execute the inner filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + public final function execute (Requestable $requestInstance, Responseable $responseInstance) { + $this->getFilterInstance()->execute($requestInstance, $responseInstance); + } + + + /** + * Do the execution of the filter + * + * @param<->$requestInstance<-->An instance of a request class + * @param<->$responseInstance<->An instance of a response class + * @return void + */ + abstract public function doExecute (Requestable $requestInstance, Responseable $responseInstance); +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php new file mode 100644 index 0000000..a335323 --- /dev/null +++ b/inc/classes/main/filter/class_FilterChain.php @@ -0,0 +1,92 @@ + + * @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 FilterChain extends BaseFrameworkSystem { + /** + * All filters together + */ + private $filters = array(); + + /** + * 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(); + } + + /** + * Creates an instance of this class + * + * @return $chainInstance An instance of this class + */ + public final static function createFilterChain () { + // Get a new instance + $chainInstance = new FilterChain(); + + // Return the prepared instance + return $chainInstance; + } + + /** + * Add a new filter + * + * @param $filerInstance An instance of a filter class + * @return void + */ + public final function addFilter (Filterable $filterInstance) { + $this->filters[] = $filterInstance; + } + + /** + * Process all added filters + * + * @param $requestInstance An instance of a request class + * @param $responseInstance An instance of a response class + * @return void + */ + public function processFilters (Requestable $requestInstance, Responseable $responseInstance) { + // Run all filters + foreach ($this->filters as $filterInstance) { + // Execute this filter + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.
\n"; + $filterInstance->execute($requestInstance, $responseInstance); + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.
\n"; + } + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/validator/.htaccess b/inc/classes/main/filter/validator/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/filter/validator/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php new file mode 100644 index 0000000..efc3fec --- /dev/null +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -0,0 +1,75 @@ + + * @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 UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable { + /** + * Private constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for username validation"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserNameValidatorFilter () { + // Get a new instance + $filterInstance = new UserNameValidatorFilter(); + + // Return the instance + return $filterInstance; + } + + /** + * Executes the filter 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 + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Implement this! + $this->partialStub("Please implement this method."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 41ad0fd..0c761d8 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -161,13 +161,11 @@ class WebFormHelper extends BaseHelper { * opened. The field's name will be set as id. * * @param $fieldName Input field name - * @param $fieldSize Input size - * @param $fieldMaxLength Input max length * @param $fieldValue Input default value (default: empty) * @return void * @throws FormClosedException If the form is not yet opened */ - public function addInputTextField ($fieldName, $fieldSize, $fieldMaxLength, $fieldValue = "") { + public function addInputTextField ($fieldName, $fieldValue = "") { // Is the form opened? if ($this->formOpened === false) { // Throw an exception @@ -175,8 +173,11 @@ class WebFormHelper extends BaseHelper { } // Generate the content - $inputContent = sprintf("", - $fieldName, $fieldName, $fieldSize, $fieldMaxLength, $fieldValue); + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); // And add it maybe with a "li" tag $this->addContent($inputContent); @@ -187,13 +188,11 @@ class WebFormHelper extends BaseHelper { * yet opened. The field's name will be set as id. * * @param $fieldName Input field name - * @param $fieldSize Input size - * @param $fieldMaxLength Input max length * @param $fieldValue Input default value (default: empty) * @return void * @throws FormClosedException If the form is not yet opened */ - public function addInputPasswordField ($fieldName, $fieldSize, $fieldMaxLength, $fieldValue = "") { + public function addInputPasswordField ($fieldName, $fieldValue = "") { // Is the form opened? if ($this->formOpened === false) { // Throw an exception @@ -201,8 +200,11 @@ class WebFormHelper extends BaseHelper { } // Generate the content - $inputContent = sprintf("", - $fieldName, $fieldName, $fieldSize, $fieldMaxLength, $fieldValue); + $inputContent = sprintf("", + $fieldName, + $fieldName, + $fieldValue + ); // And add it $this->addContent($inputContent); diff --git a/inc/classes/main/resolver/class_BaseResolver.php b/inc/classes/main/resolver/class_BaseResolver.php index d947d89..91f5c3d 100644 --- a/inc/classes/main/resolver/class_BaseResolver.php +++ b/inc/classes/main/resolver/class_BaseResolver.php @@ -94,7 +94,7 @@ class BaseResolver extends BaseFrameworkSystem { // Now, let us create the full name of the command class $class = sprintf("%s%sCommand", $this->commandPrefix, - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); // Is this class already loaded? @@ -103,6 +103,13 @@ class BaseResolver extends BaseFrameworkSystem { $isValid = true; } + // Debug output + //echo "----- ".__METHOD__." -----
\n"; + //print($class."
");
+		//debug_print_backtrace();
+		//var_dump($isValid);
+		//print("
"); + // Set command name $this->setCommandName($commandName); diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index 2ab4e50..05bcd65 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -53,23 +53,23 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { /** * Creates an instance of a Web command resolver with a given default command * - * @param $defaultCommand The default command we shall execute + * @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 createWebCommandResolver ($defaultCommand, ManageableApplication $appInstance) { + public final static function createWebCommandResolver ($commandName, ManageableApplication $appInstance) { // Create the new instance $resolverInstance = new WebCommandResolver(); - // Is the variable $defaultCommand set and the command is valid? - if (empty($defaultCommand)) { + // Is the variable $commandName set and the command is valid? + if (empty($commandName)) { // Then thrown an exception here throw new EmptyVariableException(array($resolverInstance, 'defaultCommand'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); - } elseif (!$resolverInstance->isCommandValid($defaultCommand)) { + } elseif (!$resolverInstance->isCommandValid($commandName)) { // Invalid command found - throw new InvalidCommandException(array($resolverInstance, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); + throw new InvalidCommandException(array($resolverInstance, $commandName), self::EXCEPTION_INVALID_COMMAND); } // Set the application instance @@ -145,7 +145,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Create command class name $class = sprintf("Web%sCommand", - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); // Is this class loaded? diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index 16ad0c2..06d0bcf 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -23,10 +23,15 @@ */ class WebControllerResolver extends BaseResolver implements ControllerResolver { /** - * Last successfull resolved controller + * Last successfull resolved controller (name) */ private $lastControllerName = ""; + /** + * Last successfull resolved controller (instance) + */ + private $lastControllerInstance = null; + /** * Protected constructor * @@ -114,8 +119,8 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { throw new InvalidControllerInstanceException(array($this, $commandName), self::EXCEPTION_INVALID_CONTROLLER); } - // Set last command - $this->lastCommandInstance = $controllerInstance; + // Set last controller + $this->lastControllerInstance = $controllerInstance; } catch (MissingArrayElementsException $e) { // Just catch it here... } @@ -133,6 +138,12 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { * controller class is missing (bad!) */ private function loadController ($commandName) { + // Debug message + //print("----- ".__METHOD__." -----
");
+		 //debug_print_backtrace();
+		 //print("
"); + // + // Cache default command $defaultCommand = $this->getConfigInstance()->readConfig("default_command"); @@ -146,11 +157,14 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { if ($commandName != $defaultCommand) { // Create controller class name $class = sprintf("Web%sController", - ucfirst(strtolower($commandName)) + $this->convertToClassName($commandName) ); } elseif ($this->getConfigInstance()->readConfig("home_with_news") == "Y") { // Yes, display news in home then set default controller with news $class = "WebDefaultNewsController"; + } else { + // No nes at "home" page + $class = "WebDefaultController"; } // Is this class loaded? -- 2.39.2