From: Roland Häder Date: Sun, 15 Jun 2008 19:30:22 +0000 (+0000) Subject: Login and auth classes added. WARNING: All class config entries must end with _class! X-Git-Url: https://git.mxchange.org/?p=shipsimu.git;a=commitdiff_plain;h=b848cab53db89342f0a854a00be91cadbcff2967 Login and auth classes added. WARNING: All class config entries must end with _class! --- diff --git a/.gitattributes b/.gitattributes index 578b832..bff812f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -149,6 +149,9 @@ inc/.htaccess -text inc/classes.php -text inc/classes/.htaccess -text inc/classes/exceptions/.htaccess -text +inc/classes/exceptions/auth/.htaccess -text +inc/classes/exceptions/auth/class_UserAuthorizationException.php -text +inc/classes/exceptions/class_ -text inc/classes/exceptions/class_FrameworkException.php -text inc/classes/exceptions/compressor/.htaccess -text inc/classes/exceptions/compressor/class_MismatchingCompressorsException.php -text @@ -170,6 +173,8 @@ inc/classes/exceptions/database/local_file/class_SavePathReadProtectedException. inc/classes/exceptions/database/local_file/class_SavePathWriteProtectedException.php -text inc/classes/exceptions/database/wrapper/.htaccess -text inc/classes/exceptions/database/wrapper/class_WrapperUserNameNotFoundException.php -text +inc/classes/exceptions/filter/.htaccess -text +inc/classes/exceptions/filter/class_FilterChainException.php -text inc/classes/exceptions/helper/.htaccess -text inc/classes/exceptions/helper/class_FormClosedException.php -text inc/classes/exceptions/helper/class_FormGroupClosedException.php -text @@ -232,6 +237,8 @@ inc/classes/exceptions/user/class_UsernameMissingException.php -text inc/classes/interfaces/.htaccess -text inc/classes/interfaces/application/.htaccess -text inc/classes/interfaces/application/class_ManageableApplication.php -text +inc/classes/interfaces/auth/.htaccess -text +inc/classes/interfaces/auth/class_Authorizeable.php -text inc/classes/interfaces/cache/.htaccess -text inc/classes/interfaces/cache/class_Cacheable.php -text inc/classes/interfaces/class_ -text @@ -272,6 +279,8 @@ inc/classes/interfaces/language/.htaccess -text inc/classes/interfaces/language/class_ManageableLanguage.php -text inc/classes/interfaces/login/.htaccess -text inc/classes/interfaces/login/class_LoginableUser.php -text +inc/classes/interfaces/reader/.htaccess -text +inc/classes/interfaces/reader/class_ReadableNews.php -text inc/classes/interfaces/registration/.htaccess -text inc/classes/interfaces/registration/class_UserRegister.php -text inc/classes/interfaces/registry/.htaccess -text @@ -297,6 +306,8 @@ inc/classes/main/actions/class_ -text inc/classes/main/actions/class_BaseAction.php -text inc/classes/main/actions/post_registration/.htaccess -text inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php -text +inc/classes/main/auth/.htaccess -text +inc/classes/main/auth/class_CookieAuth.php -text inc/classes/main/cache/.htaccess -text inc/classes/main/cache/class_MemoryCache.php -text inc/classes/main/class_ -text @@ -324,6 +335,8 @@ inc/classes/main/controller/default/class_WebDefaultController.php -text inc/classes/main/controller/default/class_WebDefaultNewsController.php -text inc/classes/main/controller/form/.htaccess -text inc/classes/main/controller/form/class_WebDoFormController.php -text +inc/classes/main/controller/login/.htaccess -text +inc/classes/main/controller/login/class_WebLoginAreaController.php -text inc/classes/main/criteria/.htaccess -text inc/classes/main/criteria/class_DataSetCriteria.php -text inc/classes/main/criteria/class_SearchCriteria.php -text @@ -353,12 +366,18 @@ inc/classes/main/factories/objects/class_ObjectFactory.php -text inc/classes/main/factories/web/.htaccess -text inc/classes/main/factories/web/class_WebNewsFactory.php -text inc/classes/main/filter/.htaccess -text +inc/classes/main/filter/auth/.htaccess -text +inc/classes/main/filter/auth/class_UserAuthFilter.php -text inc/classes/main/filter/checkboxes/.htaccess -text inc/classes/main/filter/checkboxes/class_RulesAcceptedFilter.php -text inc/classes/main/filter/class_ -text inc/classes/main/filter/class_AbstractFilterDecorator.php -text +inc/classes/main/filter/class_BaseFilter.php -text inc/classes/main/filter/class_FilterChain.php -text inc/classes/main/filter/decorator/.htaccess -text +inc/classes/main/filter/news/.htaccess -text +inc/classes/main/filter/news/class_NewsDownloadFilter.php -text +inc/classes/main/filter/news/class_NewsProcessFilter.php -text inc/classes/main/filter/null/.htaccess -text inc/classes/main/filter/null/class_NullFilter.php -text inc/classes/main/filter/validator/.htaccess -text @@ -379,11 +398,11 @@ inc/classes/main/io/class_FrameworkFileInputPointer.php -text inc/classes/main/io/class_FrameworkFileOutputPointer.php -text inc/classes/main/language/.htaccess -text inc/classes/main/language/class_LanguageSystem.php -text -inc/classes/main/login/.htaccess -text -inc/classes/main/login/class_CookieLogin.php -text inc/classes/main/output/.htaccess -text inc/classes/main/output/class_ConsoleOutput.php -text inc/classes/main/output/class_WebOutput.php -text +inc/classes/main/reader/.htaccess -text +inc/classes/main/reader/class_DefaultNewsReader.php -text inc/classes/main/registration/.htaccess -text inc/classes/main/registration/class_BaseRegistration.php -text inc/classes/main/registry/.htaccess -text diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index f6dab26..928fcda 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -273,7 +273,7 @@ class ApplicationSelector extends BaseFrameworkSystem { // Remember this template and the application for later usage $this->loadedTemplates->append(array( - 'tpl_engine' => $tplEngine, + 'template_class' => $tplEngine, 'app_instance' => $appInstance )); } @@ -342,9 +342,9 @@ class ApplicationSelector extends BaseFrameworkSystem { } elseif (count($curr) != 2) { // Not expected count of entries throw new InvalidArrayCountException(array($this, "curr", count($curr), 2), self::EXCEPTION_ARRAY_HAS_INVALID_COUNT); - } elseif (!isset($curr['tpl_engine']) || (!isset($curr['app_instance']))) { + } elseif (!isset($curr['template_class']) || (!isset($curr['app_instance']))) { // Expected entries missing - throw new MissingArrayElementsException(array($this, "curr", array('tpl_engine', 'app_instance')), self::EXCEPTION_ARRAY_ELEMENTS_MISSING); + throw new MissingArrayElementsException(array($this, "curr", array('template_class', 'app_instance')), self::EXCEPTION_ARRAY_ELEMENTS_MISSING); } die("
".print_r($curr, true)."
"); diff --git a/application/selector/starter.php b/application/selector/starter.php index 4bcbd4a..fcd9855 100644 --- a/application/selector/starter.php +++ b/application/selector/starter.php @@ -51,7 +51,7 @@ try { // Call user function call_user_func_array(array($app, FrameworkConfiguration::getInstance()->readConfig('entry_method')), array()); } catch (FrameworkException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s could not be launched for the follwing reason: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s has been terminated due to a thrown exception: %s", $application, $e->getMessage() )); diff --git a/application/ship-simu/class_ApplicationHelper.php b/application/ship-simu/class_ApplicationHelper.php index ef2de33..c8057d4 100644 --- a/application/ship-simu/class_ApplicationHelper.php +++ b/application/ship-simu/class_ApplicationHelper.php @@ -187,16 +187,13 @@ class ApplicationHelper extends BaseFrameworkSystem implements ManageableApplica // ... and a new response object $responseInstance = HttpResponse::createHttpResponse($this); - // Get command parameter - $commandPara = $this->getConfigInstance()->readConfig('command_parameter'); - // Get the parameter from the request - $commandName = $requestInstance->getRequestElement($commandPara); + $commandName = $requestInstance->getRequestElement("page"); // If it is null then get default command if (is_null($commandName)) { $commandName = $this->getConfigInstance()->readConfig('default_command'); - } + } // END - if // Get a resolver $resolverInstance = WebControllerResolver::createWebControllerResolver($commandName, $this); diff --git a/application/ship-simu/config.php b/application/ship-simu/config.php index a827e38..d5f7a48 100644 --- a/application/ship-simu/config.php +++ b/application/ship-simu/config.php @@ -67,26 +67,38 @@ $cfg->setConfigEntry('chat_enabled_aol', "Y"); // CFG: CHAT-ENABLED-MSN $cfg->setConfigEntry('chat_enabled_msn', "Y"); -// CFG: COMMAND-PARAMETER -$cfg->setConfigEntry('command_parameter', "page"); - // CFG: USER-REGISTRATION -$cfg->setConfigEntry('user_registration', "ShipSimuRegistration"); +$cfg->setConfigEntry('user_registration_class', "ShipSimuRegistration"); // CFG: LOGIN-USER -$cfg->setConfigEntry('login_user', "ShipSimuUserLogin"); +$cfg->setConfigEntry('user_login_class', "ShipSimuUserLogin"); // CFG: USER-STATUS-REGISTER $cfg->setConfigEntry('user_status_register', "UNCONFIRMED"); // CFG: LOGIN-HELPER -$cfg->setConfigEntry('login_helper', "ShipSimuLoginHelper"); +$cfg->setConfigEntry('login_helper_class', "ShipSimuLoginHelper"); // CFG: LOGIN-METHOD -$cfg->setConfigEntry('login_method', "cookie"); +$cfg->setConfigEntry('auth_method_class', "CookieAuth"); // CFG: APP-LOGIN-URL $cfg->setConfigEntry('app_login_url', "index.php?app=ship-simu&page=login_area"); +// CFG: LOGIN-DEFAULT-ACTION +$cfg->setConfigEntry('login_default_action', "welcome"); + +// CFG: NEWS-READER-CLASS +$cfg->setConfigEntry('news_reader_class', "DefaultNewsReader"); + +// CFG: NEWS-DOWNLOAD-FILTER +$cfg->setConfigEntry('news_download_class', "NewsDownloadFilter"); + +// CFG: NEWS-PROCESS-FILTER +$cfg->setConfigEntry('news_process_class', "NewsProcessFilter"); + +// CFG: USER-AUTH-FILTER +$cfg->setConfigEntry('user_auth_class', "UserAuthFilter"); + // [EOF] ?> diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php index 0940b79..cc9b0b7 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php @@ -59,10 +59,10 @@ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable { $controllerInstance = $resolverInstance->getControllerInstance(); // @TODO Add some more pre/post filters to the controller - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_validator')); - $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('rules_accepted_filter')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('email_validator_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('username_validator_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('password_validator_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('rules_accepted_class')); // Return the prepared instance return $commandInstance; @@ -77,7 +77,7 @@ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // First get a UserRegistration instance - $registerInstance = ObjectFactory::createObjectByConfiguredName('user_registration'); + $registerInstance = ObjectFactory::createObjectByConfiguredName('user_registration_class'); // First set request and response instance $registerInstance->setRequestInstance($requestInstance); diff --git a/application/ship-simu/main/login/class_ShipSimuUserLogin.php b/application/ship-simu/main/login/class_ShipSimuUserLogin.php index 59ddcdc..75bc8fa 100644 --- a/application/ship-simu/main/login/class_ShipSimuUserLogin.php +++ b/application/ship-simu/main/login/class_ShipSimuUserLogin.php @@ -63,7 +63,7 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { * @param $requestInstance An instance of a Requestable class * @param $responseInstance An instance of a Responseable class * @return void - * @throws UserLoginMethodException If wether username nor email login + * @throws UserAuthMethodException If wether username nor email login * was detected * @throws MissingMethodException If a method was not found in the * User class @@ -89,7 +89,7 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { // Is a method detected? if (is_null($method)) { // Then abort here - throw new UserLoginMethodException($this, self::EXCEPTION_MISSING_METHOD); + throw new UserAuthMethodException($this, self::EXCEPTION_MISSING_METHOD); } elseif (!method_exists($this->getConfigInstance()->readConfig('user_class'), $method)) { // The method is invalid! throw new MissingMethodException(array($this, $method), self::EXCEPTION_MISSING_METHOD); @@ -116,7 +116,7 @@ class ShipSimuUserLogin extends BaseFrameworkSystem implements LoginableUser { // Now do the real login. This can be cookie- or session-based login // which depends on the admins setting then on the user's taste. // 1) Get a login helper instance - $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper', array($requestInstance)); + $helperInstance = ObjectFactory::createObjectByConfiguredName('login_helper_class', array($requestInstance)); // 2) Execute the login. This will now login... $helperInstance->executeLogin($responseInstance); diff --git a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php index 9dd7f96..169f18f 100644 --- a/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php +++ b/application/ship-simu/main/login/helper/class_ShipSimuLoginHelper.php @@ -33,7 +33,7 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { /** * The login method we shall choose */ - private $loginMethod = ""; + private $authMethod = ""; /** * Instance for a request class @@ -41,7 +41,7 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { private $requestInstance = null; // Exception constants - const EXCEPTION_INVALID_USER_INSTANCE = 0xf00; + const EXCEPTION_INVALID_USER_INSTANCE = 0x080; /** * Protected constructor @@ -80,23 +80,8 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { throw new UserInstanceMissingException (array($helperInstance, 'user'), self::EXCEPTION_INVALID_USER_INSTANCE); } // END - if - // Get the login method from request - $methodRequest = $requestInstance->getRequestElement('login_method'); - - // Now, if that wents fine we can check if the request includes a login method entry - if ((!is_null($methodRequest)) && ($methodRequest != "default") && ($methodRequest != $userInstance->getLoginMethod())) { - // Okay, the login method has been choosen by user so remember it - $helperInstance->setLoginMethod($methodRequest); - - // Remeber that we need to update the user account as well - $userInstance->addUpdateData('login_method', $methodRequest); - } elseif (($methodRequest == "default") && (is_string($userInstance->getLoginMethod()))) { - // Choose default method from user - $helperInstance->setLoginMethod($userInstance->getLoginMethod()); - } else { - // Set default login method from config - $helperInstance->setDefaultLoginMethod(); - } + // Set default login method from config + $helperInstance->setDefaultAuthMethod(); // Set request instance $helperInstance->setRequestInstance($requestInstance); @@ -110,8 +95,8 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { * * @return void */ - protected function setDefaultLoginMethod () { - $this->loginMethod = $this->getConfigInstance()->readConfig('login_method'); + protected function setDefaultAuthMethod () { + $this->authMethod = $this->getConfigInstance()->readConfig('auth_method_class'); } /** @@ -142,11 +127,8 @@ class ShipSimuLoginHelper extends BaseLoginHelper implements HelpableLogin { * @return void */ public function executeLogin (Responseable $responseInstance) { - // First create the requested login method name - $loginMethodClass = ucfirst(strtolower($this->loginMethod)) . "Login"; - - // Then try to get an instance from it - $loginInstance = ObjectFactory::createObjectByName($loginMethodClass, array($responseInstance)); + // Get an instance from the login method + $loginInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance)); // Set user cookie $loginInstance->setUserAuth($this->requestInstance->getRequestElement('username')); diff --git a/application/ship-simu/main/registration/class_ShipSimuRegistration.php b/application/ship-simu/main/registration/class_ShipSimuRegistration.php index 0a8563c..aae55e7 100644 --- a/application/ship-simu/main/registration/class_ShipSimuRegistration.php +++ b/application/ship-simu/main/registration/class_ShipSimuRegistration.php @@ -93,7 +93,7 @@ class ShipSimuRegistration extends BaseRegistration { // 1.: Get the plain password $plainPassword = $this->getRequestInstance()->getRequestElement($requestKey); // 2. Get a crypto helper and hash the password - $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_heler')->hashPassword($plainPassword); + $this->hashedPassword = ObjectFactory::createObjectByConfiguredName('crypto_class')->hashPassword($plainPassword); // 3. Store the hash back in the request $this->getRequestInstance()->setRequestElement('pass_hash', $this->hashedPassword); } @@ -118,7 +118,7 @@ class ShipSimuRegistration extends BaseRegistration { */ public function registerNewUser () { // Get a user database wrapper - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); // Use this instance to insert the whole registration instance $wrapperInstance->insertRegistrationObject($this); @@ -143,7 +143,7 @@ class ShipSimuRegistration extends BaseRegistration { */ public function doPostAction () { // Get an action instance from our factory - $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_action'); + $actionInstance = ObjectFactory::createObjectByConfiguredName('post_registration_class'); // Execute the action $actionInstance->execute($this->getRequestInstance(), $this->getResponseInstance()); diff --git a/application/ship-simu/starter.php b/application/ship-simu/starter.php index 4bcbd4a..fcd9855 100644 --- a/application/ship-simu/starter.php +++ b/application/ship-simu/starter.php @@ -51,7 +51,7 @@ try { // Call user function call_user_func_array(array($app, FrameworkConfiguration::getInstance()->readConfig('entry_method')), array()); } catch (FrameworkException $e) { - ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s could not be launched for the follwing reason: %s", + ApplicationEntryPoint::app_die(sprintf("[Main:] The application %s has been terminated due to a thrown exception: %s", $application, $e->getMessage() )); diff --git a/inc/classes/exceptions/auth/.htaccess b/inc/classes/exceptions/auth/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/exceptions/auth/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/auth/class_UserAuthorizationException.php b/inc/classes/exceptions/auth/class_UserAuthorizationException.php new file mode 100644 index 0000000..5fedd40 --- /dev/null +++ b/inc/classes/exceptions/auth/class_UserAuthorizationException.php @@ -0,0 +1,46 @@ + + * @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 UserAuthorizationException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $filterInstance An instance of the filter throwing this exception + * @param $code Error code + * @return void + */ + public function __construct(Filterable $filterInstance, $code) { + // Construct the message + $message = sprintf("[%s:%d] Authorization has failed. Error code %s", + $filterInstance->__toString(), + $this->getLine(), + $this->getHexCode($code) + ); + + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/class_ b/inc/classes/exceptions/class_ new file mode 100644 index 0000000..3001d84 --- /dev/null +++ b/inc/classes/exceptions/class_ @@ -0,0 +1,39 @@ + + * @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 ???Exception extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $message Error message + * @param $code Error code + * @return void + */ + public function __construct($message, $code) { + // Call parent exception constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/exceptions/class_FrameworkException.php b/inc/classes/exceptions/class_FrameworkException.php index b7f1c5b..2c40396 100644 --- a/inc/classes/exceptions/class_FrameworkException.php +++ b/inc/classes/exceptions/class_FrameworkException.php @@ -44,7 +44,7 @@ abstract class FrameworkException extends ReflectionException { $message = (string) $message; $code = (int) $code; - // make sure everything is assigned properly + // Make sure everything is assigned properly parent::__construct($message, $code); } @@ -78,11 +78,12 @@ abstract class FrameworkException extends ReflectionException { /** * Getter for hex-decimal code * + * @param $code Integer code to encode in hex * @return $hexCode The exception code in hex-decimal format */ - public final function getHexCode () { + public final function getHexCode ($code = null) { // Get the decimal code - $code = $this->getCode(); + if (is_null($code)) $code = $this->getCode(); // Format it to hex-decimal, 0x as prefix and 3 chars $hexCode = sprintf("0x%03s", dechex($code)); diff --git a/inc/classes/exceptions/filter/.htaccess b/inc/classes/exceptions/filter/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/exceptions/filter/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/exceptions/filter/class_FilterChainException.php b/inc/classes/exceptions/filter/class_FilterChainException.php new file mode 100644 index 0000000..e1bfe10 --- /dev/null +++ b/inc/classes/exceptions/filter/class_FilterChainException.php @@ -0,0 +1,45 @@ + + * @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 FilterChainException extends FrameworkException { + /** + * The super constructor for all exceptions + * + * @param $filterInstance Instance of a filter class + * @param $code Exception code for better debugging + * @return void + */ + public function __construct(Filterable $filterInstance, $code) { + // Construct the message + $message = sprintf("[%s:%d] Filter chain interruppted by fatal error in filter.", + $filterInstance->__toString(), + $this->getLine() + ); + + // Call the parent exception + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/interfaces/auth/.htaccess b/inc/classes/interfaces/auth/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/auth/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/auth/class_Authorizeable.php b/inc/classes/interfaces/auth/class_Authorizeable.php new file mode 100644 index 0000000..88e383f --- /dev/null +++ b/inc/classes/interfaces/auth/class_Authorizeable.php @@ -0,0 +1,34 @@ + + * @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 Authorizeable extends FrameworkInterface { + /** + * Destroy the authorization data + * + * @return void + */ + function destroyAuthData(); +} + +// +?> diff --git a/inc/classes/interfaces/reader/.htaccess b/inc/classes/interfaces/reader/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/interfaces/reader/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/interfaces/reader/class_ReadableNews.php b/inc/classes/interfaces/reader/class_ReadableNews.php new file mode 100644 index 0000000..c38b702 --- /dev/null +++ b/inc/classes/interfaces/reader/class_ReadableNews.php @@ -0,0 +1,34 @@ + + * @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 ReadableNews extends FrameworkInterface { + /** + * Initializes the news reader class. This is very reader-dependent + * + * @return void + */ + function initializeReader(); +} + +// +?> diff --git a/inc/classes/interfaces/request/class_Requestable.php b/inc/classes/interfaces/request/class_Requestable.php index 41f4564..1c3d092 100644 --- a/inc/classes/interfaces/request/class_Requestable.php +++ b/inc/classes/interfaces/request/class_Requestable.php @@ -70,6 +70,14 @@ interface Requestable extends FrameworkInterface { * @return void */ function requestIsValid ($isValid = true); + + /** + * Reads a cookie and returns it's value or null if not found + * + * @param $cookieName Name of cookie we shall read + * @return $cookieValue Value of cookie or null if not found + */ + function readCookie ($cookieName); } // diff --git a/inc/classes/interfaces/response/class_Responseable.php b/inc/classes/interfaces/response/class_Responseable.php index 5fd6b50..a1fabde 100644 --- a/inc/classes/interfaces/response/class_Responseable.php +++ b/inc/classes/interfaces/response/class_Responseable.php @@ -87,6 +87,14 @@ interface Responseable extends FrameworkInterface { * @throws ResponseHeadersAlreadySentException If headers are already sent */ function redirectToConfiguredUrl ($configEntry); + + /** + * Expires the given cookie if it is set + * + * @param $cookieName Cookie to expire + * @return void + */ + function expireCookie ($cookieName); } // diff --git a/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php b/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php index 63c4450..c5f1e8a 100644 --- a/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php +++ b/inc/classes/main/actions/post_registration/class_LoginAfterRegistrationAction.php @@ -60,7 +60,7 @@ class LoginAfterRegistrationAction extends BaseAction implements Commandable { */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { // Get a login class from factory - $loginInstance = ObjectFactory::createObjectByConfiguredName('login_user'); + $loginInstance = ObjectFactory::createObjectByConfiguredName('user_login_class'); // Login the user by the request instance $loginInstance->doLogin($requestInstance, $responseInstance); diff --git a/inc/classes/main/auth/.htaccess b/inc/classes/main/auth/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/auth/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/auth/class_CookieAuth.php b/inc/classes/main/auth/class_CookieAuth.php new file mode 100644 index 0000000..6b1bf3f --- /dev/null +++ b/inc/classes/main/auth/class_CookieAuth.php @@ -0,0 +1,121 @@ + + * @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 CookieAuth extends BaseFrameworkSystem implements Authorizeable, Registerable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Cookie-based login"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this class by the given response instance + * + * @param $responseInstance An instance of a Responseable class + * @return $loginInstance An instance of this login class + */ + public final static function createCookieAuth (Responseable $responseInstance) { + // Get a new instance + $loginInstance = new CookieAuth(); + + // Set the response instance + $loginInstance->setResponseInstance($responseInstance); + + // Return the prepared instance + return $loginInstance; + } + + /** + * "Setter" for username auth data + * + * @param $userName The username from request we shall set + * @return void + */ + public function setUserAuth ($userName) { + $this->getResponseInstance()->addCookie('username', $userName); + } + + /** + * "Setter" for password hash auth data + * + * @param $passHash The hashed password from request we shall set + * @return void + */ + public function setPasswordAuth ($passHash) { + $this->getResponseInstance()->addCookie('u_hash', $passHash, true); + } + + /** + * Getter for user auth cookie + * + * @return $userName Username to get from cookie + */ + public function getUserAuth () { + // Get the username from cookie + $userName = $this->getRequestInstance()->readCookie('username'); + + // Return the username + return $userName; + } + + /** + * Getter for password hash auth cookie + * + * @return $passHash Password hash to get from cookie + */ + public function getPasswordAuth () { + // Get the username from cookie + $passHash = $this->getRequestInstance()->readCookie('u_hash'); + + // Return the username + return $passHash; + } + + /** + * Destroy the authorization data + * + * @return void + */ + public function destroyAuthData () { + // Expire both cookies + $this->getResponseInstance()->expireCookie('username'); + $this->getResponseInstance()->expireCookie('u_hash'); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/class_BaseFrameworkSystem.php b/inc/classes/main/class_BaseFrameworkSystem.php index d8d095f..3484a4e 100644 --- a/inc/classes/main/class_BaseFrameworkSystem.php +++ b/inc/classes/main/class_BaseFrameworkSystem.php @@ -32,6 +32,15 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * The language instance for the template loader */ private static $langInstance = null; + /** + * Instance of a request class + */ + private $requestInstance = null; + + /** + * Instance of a response class + */ + private $responseInstance = null; /** * The real class name @@ -267,7 +276,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { $this->systemclasses[] = $this->getConfigInstance()->readConfig('app_helper_class'); // Set debug instance - $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_engine'))); + $this->setDebugInstance(DebugMiddleware::createDebugMiddleware($this->getConfigInstance()->readConfig('debug_class'))); // Get output instance and set it $outputInstance = ObjectFactory::createObjectByConfiguredName('web_engine', array($this->getConfigInstance()->readConfig('web_content_type'))); @@ -407,6 +416,44 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { self::$applicationInstance = $applicationInstance; } + /** + * Setter for request instance + * + * @param $requestInstance An instance of a Requestable class + * @return void + */ + public final function setRequestInstance (Requestable $requestInstance) { + $this->requestInstance = $requestInstance; + } + + /** + * Getter for request instance + * + * @return $requestInstance An instance of a Requestable class + */ + public final function getRequestInstance () { + return $this->requestInstance; + } + + /** + * Setter for response instance + * + * @param $responseInstance An instance of a Responseable class + * @return void + */ + public final function setResponseInstance (Responseable $responseInstance) { + $this->responseInstance = $responseInstance; + } + + /** + * Getter for response instance + * + * @return $responseInstance An instance of a Responseable class + */ + public final function getResponseInstance () { + return $this->responseInstance; + } + /** * Getter for $realClass * @@ -821,7 +868,7 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { } // Initialize the template engine - $tplEngine = ObjectFactory::createObjectByConfiguredName('tpl_engine', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance())); + $tplEngine = ObjectFactory::createObjectByConfiguredName('template_class', array($fqfn, $appInstance->getLanguageInstance(), $appInstance->getFileIoInstance())); // Return the prepared instance return $tplEngine; @@ -886,10 +933,19 @@ class BaseFrameworkSystem extends stdClass implements FrameworkInterface { * @return $className Generated class name */ public function convertToClassName ($str) { + // Init class name $className = ""; + + // Convert all dashes in underscores + $str = str_replace("-", "_", $str); + + // Now use that underscores to get classname parts for hungarian style foreach (explode("_", $str) as $strPart) { + // Make the class name part lower case and first upper case $className .= ucfirst(strtolower($strPart)); - } + } // END - foreach + + // Return class name return $className; } diff --git a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php index da423e9..d5f45ec 100644 --- a/inc/classes/main/commands/web/class_WebLoginAreaCommand.php +++ b/inc/classes/main/commands/web/class_WebLoginAreaCommand.php @@ -66,8 +66,6 @@ class WebLoginAreaCommand extends BaseCommand implements Commandable { * @return void */ public function execute (Requestable $requestInstance, Responseable $responseInstance) { - // TODO Add basic check on authorization data here - // Default action is the one from configuration $action = sprintf("login_%s", $this->getConfigInstance()->readConfig('login_default_action')); diff --git a/inc/classes/main/controller/class_BaseController.php b/inc/classes/main/controller/class_BaseController.php index 409ded2..4438cc2 100644 --- a/inc/classes/main/controller/class_BaseController.php +++ b/inc/classes/main/controller/class_BaseController.php @@ -53,8 +53,8 @@ class BaseController extends BaseFrameworkSystem { $this->removeSystemArray(); // Initialize both filter chains - $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain'); - $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain'); + $this->preFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); + $this->postFilterChain = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); } /** diff --git a/inc/classes/main/controller/default/class_WebDefaultNewsController.php b/inc/classes/main/controller/default/class_WebDefaultNewsController.php index 326c0b0..fee2d39 100644 --- a/inc/classes/main/controller/default/class_WebDefaultNewsController.php +++ b/inc/classes/main/controller/default/class_WebDefaultNewsController.php @@ -51,6 +51,10 @@ class WebDefaultNewsController extends BaseController implements Controller { // Set the command resolver $controllerInstance->setResolverInstance($resolverInstance); + // Add news filters to this controller + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_class')); + // Return the prepared instance return $controllerInstance; } @@ -63,32 +67,24 @@ class WebDefaultNewsController extends BaseController implements Controller { * @return void */ public function handleRequest (Requestable $requestInstance, Responseable $responseInstance) { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + // Get the command instance from the resolver by sending a request instance to the resolver $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); - // Load the news here - $this->loadNewsByRequest($requestInstance); - // 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(); } - - /** - * Loads news by a given request - * - * @param $requestInstance An instance of a request class - * @return void - */ - private function loadNewsByRequest (Requestable $requestInstance) { - // Generate a new news object but not carring about which concrete we have - $newsInstance = WebNewsFactory::createFactoryByRequest($requestInstance)->createNewsObject(); - } } // [EOF] diff --git a/inc/classes/main/controller/login/.htaccess b/inc/classes/main/controller/login/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/controller/login/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/controller/login/class_WebLoginAreaController.php b/inc/classes/main/controller/login/class_WebLoginAreaController.php new file mode 100644 index 0000000..34893a1 --- /dev/null +++ b/inc/classes/main/controller/login/class_WebLoginAreaController.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 WebLoginAreaController extends BaseController implements Controller { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Default controller with news"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this class + * + * @param $resolverInstance An instance of a command resolver class + * @return $controllerInstance A prepared instance of this class + */ + public final static function createWebLoginAreaController (CommandResolver $resolverInstance) { + // Create the instance + $controllerInstance = new WebLoginAreaController(); + + // Set the command resolver + $controllerInstance->setResolverInstance($resolverInstance); + + // Add some filters to this controller + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('user_auth_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_download_class')); + $controllerInstance->addPreFilter(ObjectFactory::createObjectByConfiguredName('news_process_class')); + + // 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) { + // Run the pre filters + $this->executePreFilters($requestInstance, $responseInstance); + + // Get the command instance from the resolver by sending a request instance to the resolver + $commandInstance = $this->getResolverInstance()->resolvCommandByRequest($requestInstance); + + // 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/inc/classes/main/database/class_BaseDatabaseFrontend.php b/inc/classes/main/database/class_BaseDatabaseFrontend.php index dc54e77..2d2e04b 100644 --- a/inc/classes/main/database/class_BaseDatabaseFrontend.php +++ b/inc/classes/main/database/class_BaseDatabaseFrontend.php @@ -24,7 +24,7 @@ */ abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implements DatabaseFrontendInterface, LimitableObject { // Constants for exceptions - const EXCEPTION_SQL_QUERY = 0xc00; + const EXCEPTION_SQL_QUERY = 0x050; /** * The limiter instance diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index f599673..220ad14 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -26,8 +26,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontendInterface { // Constants for MySQL backward-compatiblity (PLEASE FIX THEM!) - const DB_CODE_TABLE_MISSING = 0x000; - const DB_CODE_TABLE_UNWRITEABLE = 0x001; + const DB_CODE_TABLE_MISSING = 0x010; + const DB_CODE_TABLE_UNWRITEABLE = 0x011; /** * Save path for "file database" diff --git a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php index cd6fa21..5fc62e2 100644 --- a/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php +++ b/inc/classes/main/database/wrapper/class_UserDatabaseWrapper.php @@ -29,7 +29,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { private $cacheInstance = null; // Constants for exceptions - const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0xe00; + const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0x070; // Constants for database columns const DB_COLUMN_USERNAME = "username"; @@ -132,7 +132,7 @@ class UserDatabaseWrapper extends BaseDatabaseWrapper { */ public function insertRegistrationObject (UserRegister $registrationInstance) { // Generate a data set for the request - $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria'); + $dataSetInstance = ObjectFactory::createObjectByConfiguredName('dataset_criteria_class'); $dataSetInstance->setTableName(self::DB_TABLE_USER); // Add registration elements to the dataset diff --git a/inc/classes/main/factories/cache/class_CacheFactory.php b/inc/classes/main/factories/cache/class_CacheFactory.php index 48f8338..e2cb7bc 100644 --- a/inc/classes/main/factories/cache/class_CacheFactory.php +++ b/inc/classes/main/factories/cache/class_CacheFactory.php @@ -66,7 +66,7 @@ class CacheFactory extends BaseFactory { */ public function createConfiguredCache () { // Read the config entry - $cacheType = $this->getConfigInstance()->readConfig("cache_type"); + $cacheType = $this->getConfigInstance()->readConfig("cache_class"); // And get a new instance $cacheInstance = ObjectFactory::createObjectByName($cacheType); diff --git a/inc/classes/main/factories/objects/class_ObjectFactory.php b/inc/classes/main/factories/objects/class_ObjectFactory.php index 024020d..9a2ec9c 100644 --- a/inc/classes/main/factories/objects/class_ObjectFactory.php +++ b/inc/classes/main/factories/objects/class_ObjectFactory.php @@ -55,14 +55,17 @@ class ObjectFactory extends BaseFactory { * @throws EmptyVariableException If a variable is empty unexpectly */ public final static function createObjectByName ($className, array $args=array()) { - // First get an instance of this factory - $factoryInstance = new ObjectFactory(); - // Is the class name valid and is the class there? if (empty($className)) { + // First get an instance of this factory + $factoryInstance = new ObjectFactory(); + // Throw an exception here throw new EmptyVariableException(array($factoryInstance, 'className'), self::EXCEPTION_UNEXPECTED_EMPTY_STRING); } elseif (!class_exists($className)) { + // First get an instance of this factory + $factoryInstance = new ObjectFactory(); + // Then throw an exception throw new ClassNotFoundException(array($factoryInstance, $className), self::EXCEPTION_CLASS_NOT_FOUND); } diff --git a/inc/classes/main/factories/web/class_WebNewsFactory.php b/inc/classes/main/factories/web/class_WebNewsFactory.php index ecd1f28..dfbb6db 100644 --- a/inc/classes/main/factories/web/class_WebNewsFactory.php +++ b/inc/classes/main/factories/web/class_WebNewsFactory.php @@ -51,67 +51,16 @@ class WebNewsFactory extends BaseFactory { * @return $factoryInstance An instance of a WebNewsFactory class */ public final static function createFactoryByRequest (Requestable $requestInstance) { - // Generate the new instance - $factoryInstance = new WebNewsFactory(); - - // Get the element name from configuration - $element = FrameworkConfiguration::getInstance()->readConfig('app_selector_get'); - - // Analyze the request, first get the Uni* application name (short one from URL) - $appName = $requestInstance->getRequestElement($element); - - // Initialize some variables - $className = ""; - $className2 = $appName; - - // Then construct the class name - foreach (array("_", "-") as $exp) { - $array = explode($exp, $className2); - foreach ($array as $el) { - $className .= ucfirst(strtolower($el)); - } - - // Copy it back and clear the class name - $className2 = $className; - $className = ""; - } - - // After all is done, copy it back and add this class' name - $className = $className2 . $factoryInstance->__toString(); + // Get the news reader class name from config + $className = $requestInstance->getConfigInstance()->readConfig('news_reader_class'); // Once we have that name, try to load initialize it - $realFactoryInstance = ObjectFactory::createObjectByName($className); - - // And assign it with the factory - $factoryInstance->setRealFactoryInstance($realFactoryInstance); + $newsInstance = ObjectFactory::createObjectByName($className, array($requestInstance)); - // Remember the request we have used for later usage - $factoryInstance->setRequestInstance($requestInstance); + // Initialize the reader + $newsInstance->initializeReader(); // Return the prepared factory instance - return $factoryInstance; - } - - /** - * Setter for the request instance - * - * @param $requestInstance An instance of a request object - * @return void - */ - public final function setRequestInstance (Requestable $requestInstance) { - $this->requestInstance = $requestInstance; - } - - /** - * Creates a new object instance and returns it - * - * @return $newsInstance An instance of a news object - */ - public function createNewsObject () { - // Ask the real factory class for doing this - $newsInstance = $this->getRealFactoryInstance()->createNewObject($this->requestInstance); - - // And return it return $newsInstance; } } diff --git a/inc/classes/main/filter/auth/.htaccess b/inc/classes/main/filter/auth/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/filter/auth/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/auth/class_UserAuthFilter.php b/inc/classes/main/filter/auth/class_UserAuthFilter.php new file mode 100644 index 0000000..5754bf1 --- /dev/null +++ b/inc/classes/main/filter/auth/class_UserAuthFilter.php @@ -0,0 +1,114 @@ + + * @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 UserAuthFilter extends BaseFilter implements Filterable { + // Exception constants + const EXCEPTION_AUTH_DATA_INVALID = 0x0a0; + + /** + * The login method we shall choose + */ + private $authMethod = ""; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A user authorization filter"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createUserAuthFilter () { + // Get a new instance + $filterInstance = new UserAuthFilter(); + + // Set default auth method + $filterInstance->setDefaultAuthMethod(); + + // Return the instance + return $filterInstance; + } + + /** + * Setter for default login method from config + * + * @return void + */ + protected function setDefaultAuthMethod () { + $this->authMethod = $this->getConfigInstance()->readConfig('auth_method_class'); + } + + /** + * 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 + * @throws UserAuthorizationException If the auth login was not found or if it was invalid + */ + public function execute (Requestable $requestInstance, Responseable $responseInstance) { + // Then get an auth instance for checking and updating the auth cookies + $authInstance = ObjectFactory::createObjectByName($this->authMethod, array($responseInstance)); + + // Set request instance + $authInstance->setRequestInstance($requestInstance); + + // Now, get the auth data for comparison + $authLogin = $authInstance->getUserAuth(); + $authHash = $authInstance->getPasswordAuth(); + + // If one is empty stop here + if ((empty($authLogin)) || (empty($authHash))) { + // Destroy the auth data + $authInstance->destroyAuthData(); + + // Mark the request as invalid + $requestInstance->requestIsValid(false); + + // Add fatal message + $responseInstance->addFatalMessage('auth_data_incomplete'); + + // Stop here + throw new UserAuthorizationException($this, self::EXCEPTION_AUTH_DATA_INVALID); + } + + // Destroy safely the auth instance + unset($authInstance); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/checkboxes/class_RulesAcceptedFilter.php b/inc/classes/main/filter/checkboxes/class_RulesAcceptedFilter.php index 3029dce..d52c6aa 100644 --- a/inc/classes/main/filter/checkboxes/class_RulesAcceptedFilter.php +++ b/inc/classes/main/filter/checkboxes/class_RulesAcceptedFilter.php @@ -23,7 +23,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class RulesAcceptedFilter extends BaseFrameworkSystem implements Filterable { +class RulesAcceptedFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -38,10 +38,6 @@ class RulesAcceptedFilter extends BaseFrameworkSystem implements Filterable { // Create unique ID number $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** @@ -76,7 +72,7 @@ class RulesAcceptedFilter extends BaseFrameworkSystem implements Filterable { // Add a message to the response $responseInstance->addFatalMessage('rules_unchecked'); - // Abort here + // Skip further processing return false; } } diff --git a/inc/classes/main/filter/class_BaseFilter.php b/inc/classes/main/filter/class_BaseFilter.php new file mode 100644 index 0000000..3800c49 --- /dev/null +++ b/inc/classes/main/filter/class_BaseFilter.php @@ -0,0 +1,45 @@ + + * @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 BaseFilter extends BaseFrameworkSystem { + // Exception constants + const EXCEPTION_FILTER_CHAIN_ABORTED = 0x090; + + /** + * Protected constructor + * + * @param $className Name of the filter class + * @return void + */ + protected function __construct ($className) { + // Call parent constructor + parent::__construct($className); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php index fa1f8f4..7004eb5 100644 --- a/inc/classes/main/filter/class_FilterChain.php +++ b/inc/classes/main/filter/class_FilterChain.php @@ -81,11 +81,16 @@ class FilterChain extends BaseFrameworkSystem { // Run all filters //* DEBUG */ echo "COUNT=".count($this->filters)."
\n"; foreach ($this->filters as $filterInstance) { - // Execute this filter - //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.
\n"; + // Try to execute this filter + try { + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing started.
\n"; $filterInstance->execute($requestInstance, $responseInstance); - //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.
\n"; - } + //* DEBUG */ echo "FILTER: ".$filterInstance->__toString().": Processing ended.
\n"; + } catch (FilterChainException $e) { + // This exception can be thrown to just skip any further processing + break; + } + } // END - foreach } } diff --git a/inc/classes/main/filter/news/.htaccess b/inc/classes/main/filter/news/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/filter/news/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/filter/news/class_NewsDownloadFilter.php b/inc/classes/main/filter/news/class_NewsDownloadFilter.php new file mode 100644 index 0000000..e3a1881 --- /dev/null +++ b/inc/classes/main/filter/news/class_NewsDownloadFilter.php @@ -0,0 +1,73 @@ + + * @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 NewsDownloadFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for downloading news"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createNewsDownloadFilter () { + // Get a new instance + $filterInstance = new NewsDownloadFilter(); + + // 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) { + // Get a news instance + $newsInstance = WebNewsFactory::createFactoryByRequest($requestInstance); + + // TODO Need to extend/rewrite this + $this->partialStub("Unfinished work."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/news/class_NewsProcessFilter.php b/inc/classes/main/filter/news/class_NewsProcessFilter.php new file mode 100644 index 0000000..8df6a0f --- /dev/null +++ b/inc/classes/main/filter/news/class_NewsProcessFilter.php @@ -0,0 +1,68 @@ + + * @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 NewsProcessFilter extends BaseFilter implements Filterable { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("A filter for processing news"); + + // Create unique ID number + $this->generateUniqueId(); + } + + /** + * Creates an instance of this filter class + * + * @return $filterInstance An instance of this filter class + */ + public final static function createNewsProcessFilter () { + // Get a new instance + $filterInstance = new NewsProcessFilter(); + + // 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) { + $this->partialStub("Unfinished work."); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/filter/null/class_NullFilter.php b/inc/classes/main/filter/null/class_NullFilter.php index 3ac6d34..ef9c70c 100644 --- a/inc/classes/main/filter/null/class_NullFilter.php +++ b/inc/classes/main/filter/null/class_NullFilter.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class NullFilter extends BaseFrameworkSystem implements Filterable { +class NullFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -37,10 +37,6 @@ class NullFilter extends BaseFrameworkSystem implements Filterable { // Create unique ID number $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** diff --git a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php index a1276c8..4785a96 100644 --- a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php @@ -24,7 +24,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable { +class EmailValidatorFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -39,10 +39,6 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable { // Create unique ID number $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** diff --git a/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php index a8369d8..1d371b1 100644 --- a/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_PasswordValidatorFilter.php @@ -22,7 +22,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -class PasswordValidatorFilter extends BaseFrameworkSystem implements Filterable { +class PasswordValidatorFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -37,10 +37,6 @@ class PasswordValidatorFilter extends BaseFrameworkSystem implements Filterable // Create unique ID number $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index 068f807..456f16a 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -24,7 +24,7 @@ * 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 { +class UserNameValidatorFilter extends BaseFilter implements Filterable { /** * Protected constructor * @@ -39,10 +39,6 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable // Create unique ID number $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); } /** diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index 718ed77..61a6243 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -49,10 +49,10 @@ class WebFormHelper extends BaseHelper { private $subGroupName = ""; // Class Constants - const EXCEPTION_FORM_NAME_INVALID = 0xb00; - const EXCEPTION_CLOSED_FORM = 0xb01; - const EXCEPTION_OPENED_FORM = 0xb02; - const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0xb03; + const EXCEPTION_FORM_NAME_INVALID = 0x030; + const EXCEPTION_CLOSED_FORM = 0x031; + const EXCEPTION_OPENED_FORM = 0x032; + const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0x033; /** * Protected constructor diff --git a/inc/classes/main/login/.htaccess b/inc/classes/main/login/.htaccess deleted file mode 100644 index 3a42882..0000000 --- a/inc/classes/main/login/.htaccess +++ /dev/null @@ -1 +0,0 @@ -Deny from all diff --git a/inc/classes/main/login/class_CookieLogin.php b/inc/classes/main/login/class_CookieLogin.php deleted file mode 100644 index cbc9203..0000000 --- a/inc/classes/main/login/class_CookieLogin.php +++ /dev/null @@ -1,99 +0,0 @@ - - * @version 0.0.0 - * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software - * @license GNU GPL 3.0 or any newer version - * @link http://www.ship-simu.org - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -class CookieLogin extends BaseFrameworkSystem implements Registerable { - /** - * Response instance - */ - private $responseInstance = null; - - /** - * Protected constructor - * - * @return void - */ - protected function __construct () { - // Call parent constructor - parent::__construct(__CLASS__); - - // Set part description - $this->setObjectDescription("Cookie-based login"); - - // Create unique ID number - $this->generateUniqueId(); - - // Clean up a little - $this->removeNumberFormaters(); - $this->removeSystemArray(); - } - - /** - * Creates an instance of this class by the given response instance - * - * @param $responseInstance An instance of a Responseable class - * @return $loginInstance An instance of this login class - */ - public final static function createCookieLogin (Responseable $responseInstance) { - // Get a new instance - $loginInstance = new CookieLogin(); - - // Set the response instance - $loginInstance->setResponseInstance($responseInstance); - - // Return the prepared instance - return $loginInstance; - } - - /** - * Setter for login instance - * - * @param $responseInstance An instance of a Responseable class - * @return void - */ - protected final function setResponseInstance (Responseable $responseInstance) { - $this->responseInstance = $responseInstance; - } - - /** - * "Setter" for username auth data - * - * @param $userName The username from request we shall set - * @return void - */ - public function setUserAuth ($userName) { - $this->responseInstance->addCookie('username', $userName); - } - - /** - * "Setter" for password hash auth data - * - * @param $passHash The hashed password from request we shall set - * @return void - */ - public function setPasswordAuth ($passHash) { - $this->responseInstance->addCookie('u_hash', $passHash, true); - } -} - -// [EOF] -?> diff --git a/inc/classes/main/reader/.htaccess b/inc/classes/main/reader/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/reader/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/reader/class_DefaultNewsReader.php b/inc/classes/main/reader/class_DefaultNewsReader.php new file mode 100644 index 0000000..7fa8ff2 --- /dev/null +++ b/inc/classes/main/reader/class_DefaultNewsReader.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 DefaultNewsReader extends BaseFrameworkSystem implements ReadableNews { + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Default news reader"); + + // Create unique ID number + $this->generateUniqueId(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Creates an instance of this reader by a provided request instance + * + * @param $requestInstance An instance of a Requestable class + * @return $readerInstance An instance of this reader class + */ + public final static function createDefaultNewsReader (Requestable $requestInstance) { + // Get a new instance + $readerInstance = new DefaultNewsReader(); + + // Set request instance + $readerInstance->setRequestInstance($requestInstance); + + // Return prepared instance + return $readerInstance; + } + + /** + * Initializes this reader class by pre-fetching news depending on "page" + * (outside or login area), which amount of news and how much to skip + * + * @return void + */ + public function initializeReader () { + // TODO Need to implement this method + } +} + +// [EOF] +?> diff --git a/inc/classes/main/registration/class_BaseRegistration.php b/inc/classes/main/registration/class_BaseRegistration.php index aec7e5a..7922530 100644 --- a/inc/classes/main/registration/class_BaseRegistration.php +++ b/inc/classes/main/registration/class_BaseRegistration.php @@ -22,16 +22,6 @@ * along with this program. If not, see . */ abstract class BaseRegistration extends BaseFrameworkSystem implements UserRegister { - /** - * Instance of a request class - */ - private $requestInstance = null; - - /** - * Instance of a response class - */ - private $responseInstance = null; - /** * Pre-registration filter chain */ @@ -64,46 +54,8 @@ abstract class BaseRegistration extends BaseFrameworkSystem implements UserRegis */ protected function initFilterChains () { // Pre/post-registration filters - $this->preRegistrationFilter = ObjectFactory::createObjectByConfiguredName('filter_chain'); - $this->postRegistrationFilter = ObjectFactory::createObjectByConfiguredName('filter_chain'); - } - - /** - * Setter for request instance - * - * @param $requestInstance An instance of a Requestable class - * @return void - */ - public final function setRequestInstance (Requestable $requestInstance) { - $this->requestInstance = $requestInstance; - } - - /** - * Getter for request instance - * - * @return $requestInstance An instance of a Requestable class - */ - public final function getRequestInstance () { - return $this->requestInstance; - } - - /** - * Setter for response instance - * - * @param $responseInstance An instance of a Responseable class - * @return void - */ - public final function setResponseInstance (Responseable $responseInstance) { - $this->responseInstance = $responseInstance; - } - - /** - * Getter for response instance - * - * @return $responseInstance An instance of a Responseable class - */ - public final function getResponseInstance () { - return $this->responseInstance; + $this->preRegistrationFilter = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); + $this->postRegistrationFilter = ObjectFactory::createObjectByConfiguredName('filter_chain_class'); } /** diff --git a/inc/classes/main/request/class_HttpRequest.php b/inc/classes/main/request/class_HttpRequest.php index e3bb312..b6f9b95 100644 --- a/inc/classes/main/request/class_HttpRequest.php +++ b/inc/classes/main/request/class_HttpRequest.php @@ -93,7 +93,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { if (!isset($this->requestData[$element])) { // Then throw an exception throw new MissingArrayElementsException(array($this, 'requestData', $element), self::EXCEPTION_MISSING_ELEMENT); - } + } // END - if // All clear return true; @@ -113,7 +113,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { try { if ($this->isRequestElementSet($element)) { $value = $this->requestData[$element]; - } + } // END - if } catch (MissingArrayElementsException $e) { // Do nothing here } @@ -158,7 +158,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { // Does this header exist? if (isset($_SERVER[$name])) { $headerValue = $_SERVER[$name]; - } + } // END - if // Return the value return $headerValue; @@ -176,7 +176,7 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { /** * Sets wether the request was valid (default: true) * - * @param $isValid Wether the request is valid + * @param $isValid Wether the request is valid * @return void */ public final function requestIsValid ($isValid = true) { @@ -191,6 +191,26 @@ class HttpRequest extends BaseFrameworkSystem implements Requestable { public final function isRequestValid () { return $this->requestIsValid; } + + /** + * Reads a cookie and returns it's value or null if not found + * + * @param $cookieName Name of cookie we shall read + * @return $cookieValue Value of cookie or null if not found + */ + public final function readCookie ($cookieName) { + // Default is no cookie with that name found + $cookieValue = null; + + // Is the cookie set? + if (isset($_COOKIE[$cookieName])) { + // Then get it + $cookieValue = $_COOKIE[$cookieName]; + } // END - if + + // Return the value + return $cookieValue; + } } // [EOF] diff --git a/inc/classes/main/resolver/web/class_WebCommandResolver.php b/inc/classes/main/resolver/web/class_WebCommandResolver.php index e551a98..f4b87a2 100644 --- a/inc/classes/main/resolver/web/class_WebCommandResolver.php +++ b/inc/classes/main/resolver/web/class_WebCommandResolver.php @@ -181,7 +181,7 @@ class WebCommandResolver extends BaseResolver implements CommandResolver { // Still not found? throw new InvalidCommandException(array($this, $defaultCommand), self::EXCEPTION_INVALID_COMMAND); } - } + } // END - if // Initiate the command $commandInstance = ObjectFactory::createObjectByName($className, array($this)); diff --git a/inc/classes/main/resolver/web/class_WebControllerResolver.php b/inc/classes/main/resolver/web/class_WebControllerResolver.php index b5f66e8..0585196 100644 --- a/inc/classes/main/resolver/web/class_WebControllerResolver.php +++ b/inc/classes/main/resolver/web/class_WebControllerResolver.php @@ -126,7 +126,9 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { } /** - * "Loads" a given controller and instances it if not yet cached + * "Loads" a given controller and instances it if not yet cached. If the + * controller was not found one of the default controllers will be used + * depending on wether news shall be displayed. * * @param $commandName A controller name we shall look for * @return $controllerInstance A loaded controller instance @@ -150,6 +152,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { $class = "WebDefaultController"; // Generate the class name + //* DEBUG: */ echo __METHOD__.": Command=".$commandName; if ($commandName != $defaultCommand) { // Create controller class name $class = sprintf("Web%sController", @@ -162,6 +165,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { // No nes at "home" page $class = "WebDefaultController"; } + //* DEBUG: */ echo ", controller=".$class."
\n"; // Is this class loaded? if (!class_exists($class)) { @@ -176,7 +180,7 @@ class WebControllerResolver extends BaseResolver implements ControllerResolver { } // END - if // Initiate the resolver and controller - $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver', array($commandName, $this->getApplicationInstance())); + $resolverInstance = ObjectFactory::createObjectByConfiguredName('web_cmd_resolver_class', array($commandName, $this->getApplicationInstance())); $controllerInstance = ObjectFactory::createObjectByName($class, array($resolverInstance)); // Remove resolver diff --git a/inc/classes/main/response/class_HttpResponse.php b/inc/classes/main/response/class_HttpResponse.php index f4a3d50..3fc5d2d 100644 --- a/inc/classes/main/response/class_HttpResponse.php +++ b/inc/classes/main/response/class_HttpResponse.php @@ -243,10 +243,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { * @param $cookieName Cookie's name * @param $cookieValue Value to store in the cookie * @param $encrypted Do some extra encryption on the value + * @param $expires Timestamp of expiration (default: configured) * @return void * @throws ResponseHeadersAlreadySentException If headers are already sent */ - public function addCookie ($cookieName, $cookieValue, $encrypted = false) { + public function addCookie ($cookieName, $cookieValue, $encrypted = false, $expires = null) { // Are headers already sent? if (headers_sent()) { // Throw an exception here @@ -261,8 +262,11 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { // For slow browsers set the cookie array element first $_COOKIE[$cookieName] = $cookieValue; - // Get a config entries - $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); + // Get all config entries + if (is_null($expires)) { + $expires = (time() + $this->getConfigInstance()->readConfig('cookie_expire')); + } // END - if + $path = $this->getConfigInstance()->readConfig('cookie_path'); $domain = $this->getConfigInstance()->readConfig('cookie_domain'); @@ -324,6 +328,23 @@ class HttpResponse extends BaseFrameworkSystem implements Responseable { // All done here... exit(); } + + /** + * Expires the given cookie if it is set + * + * @param $cookieName Cookie to expire + * @return void + */ + public function expireCookie ($cookieName) { + // Is the cookie there? + if (isset($_COOKIE[$cookieName])) { + // Then expire it with 20 minutes past + $this->addCookie($cookieName, "", false, (time() - 1200)); + + // Remove it from array + unset($_COOKIE[$cookieName]); + } // END - if + } } // [EOF] diff --git a/inc/classes/main/template/class_TemplateEngine.php b/inc/classes/main/template/class_TemplateEngine.php index 85632a4..fad4cf4 100644 --- a/inc/classes/main/template/class_TemplateEngine.php +++ b/inc/classes/main/template/class_TemplateEngine.php @@ -109,9 +109,9 @@ class TemplateEngine extends BaseFrameworkSystem implements CompileableTemplate private $helpers = array(); // Exception codes for the template engine - const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0xa00; - const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0xa01; - const EXCEPTION_INVALID_VIEW_HELPER = 0xa02; + const EXCEPTION_TEMPLATE_TYPE_IS_UNEXPECTED = 0x020; + const EXCEPTION_TEMPLATE_CONTAINS_INVALID_VAR = 0x021; + const EXCEPTION_INVALID_VIEW_HELPER = 0x022; /** * Protected constructor diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 302c117..cc9c443 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -33,9 +33,9 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { private $email = ""; // Exceptions - const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; - const EXCEPTION_USER_EMAIL_NOT_FOUND = 0xd01; - const EXCEPTION_USER_PASS_MISMATCH = 0xd02; + const EXCEPTION_USERNAME_NOT_FOUND = 0x060; + const EXCEPTION_USER_EMAIL_NOT_FOUND = 0x061; + const EXCEPTION_USER_PASS_MISMATCH = 0x062; /** * Protected constructor @@ -152,10 +152,10 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $exists = false; // Get a UserDatabaseWrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); // Create a search criteria - $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria'); + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Add the username as a criteria and set limit to one entry $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUsername()); @@ -184,10 +184,10 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $exists = false; // Get a UserDatabaseWrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); // Create a search criteria - $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria'); + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Add the username as a criteria and set limit to one entry $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_EMAIL, $this->getEmail()); @@ -218,10 +218,10 @@ class User extends BaseFrameworkSystem implements ManageableUser, Registerable { $matches = false; // Get a UserDatabaseWrapper instance - $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper'); + $wrapperInstance = ObjectFactory::createObjectByConfiguredName('user_db_wrapper_class'); // Create a search criteria - $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria'); + $criteriaInstance = ObjectFactory::createObjectByConfiguredName('search_criteria_class'); // Add the username as a criteria and set limit to one entry $criteriaInstance->addCriteria(UserDatabaseWrapper::DB_COLUMN_USERNAME, $this->getUserName()); diff --git a/inc/classes/middleware/io/class_FileIoHandler.php b/inc/classes/middleware/io/class_FileIoHandler.php index dcac291..99cb434 100644 --- a/inc/classes/middleware/io/class_FileIoHandler.php +++ b/inc/classes/middleware/io/class_FileIoHandler.php @@ -68,8 +68,8 @@ class FileIoHandler extends BaseMiddleware { $ioHandler = new FileIoHandler(); // Set the *real* file IO instances (both the same) - $ioHandler->setInputStream(ObjectFactory::createObjectByConfiguredName('file_input_stream')); - $ioHandler->setOutputStream(ObjectFactory::createObjectByConfiguredName('file_output_stream')); + $ioHandler->setInputStream(ObjectFactory::createObjectByConfiguredName('file_input_class')); + $ioHandler->setOutputStream(ObjectFactory::createObjectByConfiguredName('file_output_class')); // Return instance return $ioHandler; diff --git a/inc/config.php b/inc/config.php index d1b71f6..5057162 100644 --- a/inc/config.php +++ b/inc/config.php @@ -65,9 +65,6 @@ $cfg->setConfigEntry('raw_template_extension', ".tpl"); // CFG: CODE-TEMPLATE-EXTENSION $cfg->setConfigEntry('code_template_extension', ".ctp"); -// CFG: SELECTOR-GET -$cfg->setConfigEntry('app_selector_get', "app"); - // CFG: SELECTOR-PATH $cfg->setConfigEntry('selector_path', "selector"); @@ -93,10 +90,10 @@ $cfg->setConfigEntry('application_path', "application"); $cfg->setConfigEntry('compile_output_path', "templates/_compiled/"); // DON'T MISS THE TRAILING SLASH! // CFG: TEMPLATE-ENGINE -$cfg->setConfigEntry('tpl_engine', "TemplateEngine"); +$cfg->setConfigEntry('template_class', "TemplateEngine"); // CFG: DEBUG-ENGINE -$cfg->setConfigEntry('debug_engine', "DebugWebOutput"); +$cfg->setConfigEntry('debug_class', "DebugWebOutput"); // CFG: DEFAULT-LANGUAGE $cfg->setConfigEntry('default_lang', "de"); // A two-char language string: de for german, en for english and so on @@ -153,49 +150,49 @@ $cfg->setConfigEntry('default_application', "selector"); $cfg->setConfigEntry('verbose_level', 0); // CFG: CACHE-TYPE -$cfg->setConfigEntry('cache_type', "MemoryCache"); +$cfg->setConfigEntry('cache_class', "MemoryCache"); // CFG: SEARCH-CRITERIA -$cfg->setConfigEntry('search_criteria', "SearchCriteria"); +$cfg->setConfigEntry('search_criteria_class', "SearchCriteria"); // CFG: DATASET-CRITERIA -$cfg->setConfigEntry('dataset_criteria', "DataSetCriteria"); +$cfg->setConfigEntry('dataset_criteria_class', "DataSetCriteria"); // CFG: FILE-IO-HANDLER -$cfg->setConfigEntry('file_io_handler', "FileIoHandler"); +$cfg->setConfigEntry('file_io_class', "FileIoHandler"); // CFG: FILTER-CHAIN -$cfg->setConfigEntry('filter_chain', "FilterChain"); +$cfg->setConfigEntry('filter_chain_class', "FilterChain"); // CFG: FILE-INPUT-STREAM -$cfg->setConfigEntry('file_input_stream', "FileIoStream"); +$cfg->setConfigEntry('file_input_class', "FileIoStream"); // CFG: FILE-OUTPUT-STREAM -$cfg->setConfigEntry('file_output_stream', "FileIoStream"); +$cfg->setConfigEntry('file_output_class', "FileIoStream"); // CFG: EMAIL-VALIDATOR -$cfg->setConfigEntry('email_validator', "EmailValidatorFilter"); +$cfg->setConfigEntry('email_validator_class', "EmailValidatorFilter"); // CFG: USERNAME-VALIDATOR -$cfg->setConfigEntry('username_validator', "UserNameValidatorFilter"); +$cfg->setConfigEntry('username_validator_class', "UserNameValidatorFilter"); // CFG: PASSWORD-VALIDATOR -$cfg->setConfigEntry('password_validator', "PasswordValidatorFilter"); +$cfg->setConfigEntry('password_validator_class', "PasswordValidatorFilter"); // CFG: RULES-ACCEPTED-FILTER -$cfg->setConfigEntry('rules_accepted_filter', "RulesAcceptedFilter"); +$cfg->setConfigEntry('rules_accepted_class', "RulesAcceptedFilter"); // CFG: CRYPTO-HELPER -$cfg->setConfigEntry('crypto_heler', "CryptoHelper"); +$cfg->setConfigEntry('crypto_class', "CryptoHelper"); // CFG: RNG-CLASS $cfg->setConfigEntry('rng_class', "RandomNumberGenerator"); // CFG: USER-DB-WRAPPER -$cfg->setConfigEntry('user_db_wrapper', "UserDatabaseWrapper"); +$cfg->setConfigEntry('user_db_wrapper_class', "UserDatabaseWrapper"); // CFG: WEB-CMD-RESOLVER -$cfg->setConfigEntry('web_cmd_resolver', "WebCommandResolver"); +$cfg->setConfigEntry('web_cmd_resolver_class', "WebCommandResolver"); // CFG: MATH-PRIME $cfg->setConfigEntry('math_prime', 591623); @@ -216,7 +213,7 @@ $cfg->setConfigEntry('hash_mask', "%1s:%2s:%3s"); // 1=salt, 2=extra salt, 3=pla $cfg->setConfigEntry('is_single_server', "Y"); // CFG: POST-REGISTRATION-ACTION -$cfg->setConfigEntry('post_registration_action', "LoginAfterRegistrationAction"); +$cfg->setConfigEntry('post_registration_class', "LoginAfterRegistrationAction"); // CFG: USER-CLASS $cfg->setConfigEntry('user_class', "User"); diff --git a/inc/config/class_FrameworkConfiguration.php b/inc/config/class_FrameworkConfiguration.php index 794925d..50a4ac1 100644 --- a/inc/config/class_FrameworkConfiguration.php +++ b/inc/config/class_FrameworkConfiguration.php @@ -39,8 +39,8 @@ class FrameworkConfiguration implements Registerable { private static $cfgInstance = null; // Some constants for the configuration system - const EXCEPTION_CONFIG_ENTRY_IS_EMPTY = 0xc00; - const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0xc01; + const EXCEPTION_CONFIG_ENTRY_IS_EMPTY = 0x040; + const EXCEPTION_CONFIG_ENTRY_WAS_NOT_FOUND = 0x041; /** * Protected constructor diff --git a/inc/file_io.php b/inc/file_io.php index 7713c63..afb4161 100644 --- a/inc/file_io.php +++ b/inc/file_io.php @@ -25,7 +25,7 @@ */ // Get the instance -$io = ObjectFactory::createObjectByConfiguredName('file_io_handler'); +$io = ObjectFactory::createObjectByConfiguredName('file_io_class'); // [EOF] ?> diff --git a/inc/includes.php b/inc/includes.php index 96e6aba..a9af02b 100644 --- a/inc/includes.php +++ b/inc/includes.php @@ -29,14 +29,14 @@ $cfg = FrameworkConfiguration::getInstance(); require(sprintf("%sinc/loader/class_ClassLoader%s", PATH, $cfg->readConfig('php_extension'))); // Does the user has an application specified? -if (!empty($_GET[$cfg->readConfig('app_selector_get')])) { +if (!empty($_GET['app'])) { // Set the application from string - $application = (string) $_GET[$cfg->readConfig('app_selector_get')]; + $application = (string) $_GET['app']; } elseif (!empty($_SERVER['argv'][1])) { // Set the application from string $application = (string) $_SERVER['argv'][1]; $app = explode('=', trim($application)); - if ($app[0] == $cfg->readConfig('app_selector_get')) { + if ($app[0] == 'app') { // Application is valid! $application = trim($app[1]); } else { diff --git a/inc/loader/class_ClassLoader.php b/inc/loader/class_ClassLoader.php index 4eb1223..fa9c771 100644 --- a/inc/loader/class_ClassLoader.php +++ b/inc/loader/class_ClassLoader.php @@ -102,6 +102,11 @@ class ClassLoader { */ private $classCacheFQFN = ""; + /** + * Counter for loaded include files + */ + private $total = 0; + /** * The *public* constructor * @@ -306,6 +311,9 @@ class ClassLoader { // File is found so load it only once require($this->classes[$fileName]); + // Count this include + $this->total++; + // Developer mode excludes caching (better debugging) if (!defined('DEVELOPER')) { // Mark this class as loaded @@ -335,6 +343,15 @@ class ClassLoader { } // END - if } // END - foreach } + + /** + * Getter for total include counter + * + * @return $total Total loaded include files + */ + public final function getTotal () { + return $this->total; + } } // [EOF] diff --git a/inc/output.php b/inc/output.php index 32eb1e5..35b9359 100644 --- a/inc/output.php +++ b/inc/output.php @@ -23,7 +23,7 @@ */ // Get a debugger instance -$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig('debug_engine')); +$debug = DebugMiddleware::createDebugMiddleware(FrameworkConfiguration::getInstance()->readConfig('debug_class')); // Empty string should be ignored and used for testing the middleware DebugMiddleware::getInstance()->output(""); diff --git a/templates/de/code/emergency_exit.ctp b/templates/de/code/emergency_exit.ctp index 29725af..406c2b8 100644 --- a/templates/de/code/emergency_exit.ctp +++ b/templates/de/code/emergency_exit.ctp @@ -24,6 +24,10 @@
Total objects: $content[total_objects]
+
+ Loaded class files: $content[total_includes] + (Including exception and interfaces.) +
{?footer_msg:footer_msg="Please contact the support and supply the full above message, if you think you are not qualified to fix this problem."?} diff --git a/templates/de/code/header.ctp b/templates/de/code/header.ctp index cce8460..2561392 100644 --- a/templates/de/code/header.ctp +++ b/templates/de/code/header.ctp @@ -1,5 +1,5 @@ - + $content[title]