From b1583f59560e2878c10df2c485cc3a63a309ac3c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 31 May 2008 15:13:56 +0000 Subject: [PATCH] Renamed a folder, database client added --- .gitattributes | 10 ++- .../database/clients}/.htaccess | 0 .../class_ClientUserNameNotFoundException.php | 47 ++++++++++++ inc/classes/main/database/class_ | 48 +++++++++++++ .../database/class_BaseDatabaseClient.php | 41 +++++++++++ inc/classes/main/database/clients/.htaccess | 1 + .../clients/class_UserDatabaseClient.php | 72 +++++++++++++++++++ inc/classes/main/database/databases/.htaccess | 1 + .../class_LocalFileDatabase.php | 0 .../class_UserNameValidatorFilter.php | 3 - inc/classes/main/user/class_User.php | 24 ++++++- 11 files changed, 241 insertions(+), 6 deletions(-) rename inc/classes/{main/database/classes => exceptions/database/clients}/.htaccess (100%) create mode 100644 inc/classes/exceptions/database/clients/class_ClientUserNameNotFoundException.php create mode 100644 inc/classes/main/database/class_ create mode 100644 inc/classes/main/database/class_BaseDatabaseClient.php create mode 100644 inc/classes/main/database/clients/.htaccess create mode 100644 inc/classes/main/database/clients/class_UserDatabaseClient.php create mode 100644 inc/classes/main/database/databases/.htaccess rename inc/classes/main/database/{classes => databases}/class_LocalFileDatabase.php (100%) diff --git a/.gitattributes b/.gitattributes index 332a418..d919845 100644 --- a/.gitattributes +++ b/.gitattributes @@ -151,6 +151,8 @@ inc/classes/exceptions/container/class_ContainerMaybeDamagedException.php -text inc/classes/exceptions/controller/.htaccess -text inc/classes/exceptions/controller/class_DefaultControllerException.php -text inc/classes/exceptions/database/.htaccess -text +inc/classes/exceptions/database/clients/.htaccess -text +inc/classes/exceptions/database/clients/class_ClientUserNameNotFoundException.php -text inc/classes/exceptions/database/local_file/.htaccess -text inc/classes/exceptions/database/local_file/class_SavePathIsEmptyException.php -text inc/classes/exceptions/database/local_file/class_SavePathIsNoDirectoryException.php -text @@ -282,9 +284,13 @@ 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/database/.htaccess -text +inc/classes/main/database/class_ -text +inc/classes/main/database/class_BaseDatabaseClient.php -text inc/classes/main/database/class_BaseDatabaseFrontend.php -text -inc/classes/main/database/classes/.htaccess -text -inc/classes/main/database/classes/class_LocalFileDatabase.php -text +inc/classes/main/database/clients/.htaccess -text +inc/classes/main/database/clients/class_UserDatabaseClient.php -text +inc/classes/main/database/databases/.htaccess -text +inc/classes/main/database/databases/class_LocalFileDatabase.php -text inc/classes/main/debug/.htaccess -text inc/classes/main/debug/class_DebugConsoleOutput.php -text inc/classes/main/debug/class_DebugErrorLogOutput.php -text diff --git a/inc/classes/main/database/classes/.htaccess b/inc/classes/exceptions/database/clients/.htaccess similarity index 100% rename from inc/classes/main/database/classes/.htaccess rename to inc/classes/exceptions/database/clients/.htaccess diff --git a/inc/classes/exceptions/database/clients/class_ClientUserNameNotFoundException.php b/inc/classes/exceptions/database/clients/class_ClientUserNameNotFoundException.php new file mode 100644 index 0000000..d6fe7ed --- /dev/null +++ b/inc/classes/exceptions/database/clients/class_ClientUserNameNotFoundException.php @@ -0,0 +1,47 @@ + + * @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 ClientUserNameNotFoundException extends FrameworkException { + /** + * The constructor + * + * @param $msgArray Message from the exception + * @param $code Code number for the exception + * @return void + */ + public function __construct (array $msgArray, $code) { + // Add a message around the missing class + $message = sprintf("[%s:%d] Username %s was not found. Requesting class: %s", + $msgArray[0]->__toString(), + $this->getLine(), + $msgArray[1]->getUserName(), + $msgArray[1]->__toString() + ); + + // Call parent constructor + parent::__construct($message, $code); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/class_ b/inc/classes/main/database/class_ new file mode 100644 index 0000000..661b38f --- /dev/null +++ b/inc/classes/main/database/class_ @@ -0,0 +1,48 @@ + + * @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 extends BaseDatabaseFrontend { + /** + * Protected constructor + * + * @return void + */ + protected function __construct($class) { + // Call parent constructor + parent::constructor(__CLASS__); + + // Set part description + $this->setObjectDescription(""); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/class_BaseDatabaseClient.php b/inc/classes/main/database/class_BaseDatabaseClient.php new file mode 100644 index 0000000..8117c38 --- /dev/null +++ b/inc/classes/main/database/class_BaseDatabaseClient.php @@ -0,0 +1,41 @@ + + * @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 BaseDatabaseClient extends BaseFrameworkSystem { + /** + * Protected constructor + * + * @return void + */ + protected function __construct($class) { + // Call parent constructor + parent::__construct($class); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/clients/.htaccess b/inc/classes/main/database/clients/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/database/clients/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/database/clients/class_UserDatabaseClient.php b/inc/classes/main/database/clients/class_UserDatabaseClient.php new file mode 100644 index 0000000..2790d85 --- /dev/null +++ b/inc/classes/main/database/clients/class_UserDatabaseClient.php @@ -0,0 +1,72 @@ + + * @version 0.0.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.ship-simu.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +class UserDatabaseClient extends BaseDatabaseClient { + // Constants + const EXCEPTION_CLIENT_USERNAME_NOT_FOUND = 0xe00; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct() { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Database client for user objects"); + + // Create unique ID number + $this->createUniqueID(); + } + + /** + * Creates an instance of this database client by a provided user class + * + * @param $userInstance An instance of a user class + * @return $clientInstance An instance of the created client class + * @throws ClientUserNameNotFoundException If the supplied username + * does not exist + */ + public final static function createUserDatabaseClient (ManageableUser $userInstance) { + // Get a new instance + $clientInstance = new UserDatabaseClient(); + + // Does the username exists? + if (!$clientInstance->ifUserNameExists($userInstance->getUserName())) { + // Throw an exception here + throw new ClientUserNameNotFoundException (array($clientInstance, $userInstance), self::EXCEPTION_CLIENT_USERNAME_NOT_FOUND); + } + + // The user exists + $clientInstance->partialStub("Add loading of full user details"); + + // Return the instance + return $clientInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/database/databases/.htaccess b/inc/classes/main/database/databases/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/database/databases/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/database/classes/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php similarity index 100% rename from inc/classes/main/database/classes/class_LocalFileDatabase.php rename to inc/classes/main/database/databases/class_LocalFileDatabase.php diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index 1c7c54a..165a9ef 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -117,9 +117,6 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable } catch (UsernameMissingException $e) { // Okay, this user is missing! $alreadyTaken = false; - } catch (FrameworkException $e) { - // Something bad happend - ApplicationEntryPoint::app_die(sprintf("Exception: %s", $e->__toString())); } // Return the result diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index 53e8b46..3a31883 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -92,11 +92,33 @@ class User extends BaseFrameworkSystem implements ManageableUser { /** * Getter for username * - * @return $userName The username to set + * @return $userName The username to get */ public final function getUsername () { return $this->userNane; } + + /** + * Determines wether the username exists or not + * + * @return $exists Wether the username exists + */ + protected function ifUsernameExists () { + // By default the username does exist + $exists = true; + + // Try to get a UserDatabaseClient object back + try { + // Get the instance by providing this class + $this->userClient = UserDatabaseClient::createUserDatabaseClient($this); + } catch (ClientUserNameNotFoundException $e) { + // Does not exist! + $exists = false; + } + + // Return the status + return $exists; + } } // [EOF] -- 2.39.2