From 6c783b879094b6385da1b0a0b802c779f4870d4a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 2 Jun 2008 17:27:16 +0000 Subject: [PATCH] Registry introduces, comments fixed ;) --- .gitattributes | 2 + .../selector/class_ApplicationSelector.php | 2 +- .../web/class_WebShipsimuRegisterCommand.php | 2 +- inc/classes/main/cache/class_MemoryCache.php | 2 +- .../form/class_WebDoFormController.php | 2 +- .../main/criteria/class_SearchCriteria.php | 2 +- .../databases/class_LocalFileDatabase.php | 4 +- .../extended/class_SerializationContainer.php | 10 +-- .../filter/class_AbstractFilterDecorator.php | 2 +- inc/classes/main/filter/class_FilterChain.php | 2 +- .../validator/class_EmailValidatorFilter.php | 27 +++++++- .../class_UserNameValidatorFilter.php | 22 ++++-- inc/classes/main/helper/class_BaseHelper.php | 2 +- .../main/helper/web/class_WebFormHelper.php | 2 +- inc/classes/main/registry/.htaccess | 1 + inc/classes/main/registry/class_Registry.php | 68 +++++++++++++++++++ .../main/result/class_DatabaseResult.php | 2 +- inc/classes/main/user/class_User.php | 2 +- .../middleware/class_BaseMiddleware.php | 2 +- .../compressor/class_CompressorChannel.php | 18 ++++- .../debug/class_DebugMiddleware.php | 2 +- 21 files changed, 147 insertions(+), 31 deletions(-) create mode 100644 inc/classes/main/registry/.htaccess create mode 100644 inc/classes/main/registry/class_Registry.php diff --git a/.gitattributes b/.gitattributes index ec7d663..056bd05 100644 --- a/.gitattributes +++ b/.gitattributes @@ -342,6 +342,8 @@ inc/classes/main/language/class_LanguageSystem.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/registry/.htaccess -text +inc/classes/main/registry/class_Registry.php -text inc/classes/main/request/.htaccess -text inc/classes/main/request/class_HttpRequest.php -text inc/classes/main/resolver/.htaccess -text diff --git a/application/selector/class_ApplicationSelector.php b/application/selector/class_ApplicationSelector.php index 03e03ef..f23ae76 100644 --- a/application/selector/class_ApplicationSelector.php +++ b/application/selector/class_ApplicationSelector.php @@ -50,7 +50,7 @@ class ApplicationSelector extends BaseFrameworkSystem { ); /** - * The private constructor. No direct instances can be created from this. + * The protected constructor. No direct instances can be created from this. * * @return void */ diff --git a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php index 7279053..a419393 100644 --- a/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php +++ b/application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php @@ -23,7 +23,7 @@ */ class WebShipsimuRegisterCommand extends BaseCommand implements Commandable { /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/cache/class_MemoryCache.php b/inc/classes/main/cache/class_MemoryCache.php index 7da2e16..68a4122 100644 --- a/inc/classes/main/cache/class_MemoryCache.php +++ b/inc/classes/main/cache/class_MemoryCache.php @@ -28,7 +28,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable { private $dataCache = null; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/controller/form/class_WebDoFormController.php b/inc/classes/main/controller/form/class_WebDoFormController.php index 9ffcf78..8d46880 100644 --- a/inc/classes/main/controller/form/class_WebDoFormController.php +++ b/inc/classes/main/controller/form/class_WebDoFormController.php @@ -23,7 +23,7 @@ */ class WebDoFormController extends BaseController implements Controller { /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/criteria/class_SearchCriteria.php b/inc/classes/main/criteria/class_SearchCriteria.php index a2f0910..9d65fa8 100644 --- a/inc/classes/main/criteria/class_SearchCriteria.php +++ b/inc/classes/main/criteria/class_SearchCriteria.php @@ -40,7 +40,7 @@ class SearchCriteria extends BaseFrameworkSystem implements LocalCriteria { private $skip = 0; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/database/databases/class_LocalFileDatabase.php b/inc/classes/main/database/databases/class_LocalFileDatabase.php index 6133051..9590b62 100644 --- a/inc/classes/main/database/databases/class_LocalFileDatabase.php +++ b/inc/classes/main/database/databases/class_LocalFileDatabase.php @@ -63,8 +63,8 @@ class LocalFileDatabase extends BaseDatabaseFrontend implements DatabaseFrontend private $lastException = null; /** - * The private constructor. Do never instance from outside! - * You need to set a local file path. The class will then validate it. + * The protected constructor. Do never instance from outside! You need to + * set a local file path. The class will then validate it. * * @return void */ diff --git a/inc/classes/main/extended/class_SerializationContainer.php b/inc/classes/main/extended/class_SerializationContainer.php index b212ccd..136c07b 100644 --- a/inc/classes/main/extended/class_SerializationContainer.php +++ b/inc/classes/main/extended/class_SerializationContainer.php @@ -24,11 +24,11 @@ */ class SerializationContainer extends FrameworkArrayObject { /** - * Public constructor, if you like to have an object of this class... + * Protected constructor, please use the factory method belo! * * @return void */ - public function __construct () { + protected function __construct () { // Call parent constructor parent::__construct(__CLASS__); } @@ -39,9 +39,9 @@ class SerializationContainer extends FrameworkArrayObject { * hold the attributed and their values which we have specified in * the limitation object. * - * @param $limitInstance The instance to the object ObjectLimits - * @param $object The origin object. We don't touch it here. - * @return $containerInstance An instance of SerializationContainer + * @param $limitInstance The instance to the object ObjectLimits + * @param $object The origin object. We don't touch it here. + * @return $containerInstance An instance of SerializationContainer * @throws GetterNotFoundException If a getter was not found */ public final static function createSerializationContainer (ObjectLimits $limitInstance, FrameworkInterface $object) { diff --git a/inc/classes/main/filter/class_AbstractFilterDecorator.php b/inc/classes/main/filter/class_AbstractFilterDecorator.php index a9a1d4a..025c3de 100644 --- a/inc/classes/main/filter/class_AbstractFilterDecorator.php +++ b/inc/classes/main/filter/class_AbstractFilterDecorator.php @@ -28,7 +28,7 @@ abstract class AbstractFilterDecorator extends BaseFrameworkSystem implements Fi private $filterInstance = null; /** - * Private constructor + * Protected constructor * * @param $className Name of the real class' name * @return void diff --git a/inc/classes/main/filter/class_FilterChain.php b/inc/classes/main/filter/class_FilterChain.php index cf2ff3b..cb1ac38 100644 --- a/inc/classes/main/filter/class_FilterChain.php +++ b/inc/classes/main/filter/class_FilterChain.php @@ -28,7 +28,7 @@ class FilterChain extends BaseFrameworkSystem { private $filters = array(); /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php index 4b982b0..a2f5628 100644 --- a/inc/classes/main/filter/validator/class_EmailValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_EmailValidatorFilter.php @@ -26,7 +26,7 @@ */ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable { /** - * Private constructor + * Protected constructor * * @return void */ @@ -128,13 +128,34 @@ class EmailValidatorFilter extends BaseFrameworkSystem implements Filterable { /** * Check wether the email as already been taken * - * @param $email Email to check for existence + * @param $email Email to check for existence * @return $alreadyTaken Wether the email has been taken */ private function ifEmailIsTaken ($email) { // Default is already taken $alreadyTaken = true; - $this->partialStub(sprintf("Email: %s", $email)); + + // Get a registry instance + $registry = Registry::getInstance(); + + // Is the user already there? + if ($registry->keyExists('userInstance')) { + // Use the instance for checking for the email + $userInstance = $registry->getInstance('userInstance'); + $userInstance->setEmailAddress($email); + } else { + // If this instance is created then the username *does* exist + $userInstance = User::createUserByEmail($userName); + + // Remember this user instance in our registry for later usage + $registry->addInstance('userInstance', $userInstance); + } + + // Does the email exist? + if (!$userInstance->ifEmailAddressExists()) { + // This email has not being used yet + $alreadyTaken = false; + } // Return the result return $alreadyTaken; diff --git a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php index fab9eef..cb82296 100644 --- a/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php +++ b/inc/classes/main/filter/validator/class_UserNameValidatorFilter.php @@ -26,7 +26,7 @@ */ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable { /** - * Private constructor + * Protected constructor * * @return void */ @@ -110,12 +110,24 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable // Default is already taken $alreadyTaken = true; - // Try to create a user instance - try { + // Get a registry instance + $registry = Registry::getInstance(); + + // Is the user already there? + if ($registry->instanceExists('user')) { + // Use the instance for checking for the email + $userInstance = $registry->getInstance('user'); + } else { // If this instance is created then the username *does* exist $userInstance = User::createUserByUsername($userName); - } catch (UsernameMissingException $e) { - // Okay, this user is missing! + + // Remember this user instance in our registry for later usage + $registry->addInstance('user', $userInstance); + } + + // Does the username exist? + if (!$userInstance->ifUsernameExists()) { + // This username is still available $alreadyTaken = false; } diff --git a/inc/classes/main/helper/class_BaseHelper.php b/inc/classes/main/helper/class_BaseHelper.php index 02a99e3..1a48194 100644 --- a/inc/classes/main/helper/class_BaseHelper.php +++ b/inc/classes/main/helper/class_BaseHelper.php @@ -33,7 +33,7 @@ class BaseHelper extends BaseFrameworkSystem { private $content = ""; /** - * Private constructor + * Protected constructor * * @param $className Real name of the class * @return void diff --git a/inc/classes/main/helper/web/class_WebFormHelper.php b/inc/classes/main/helper/web/class_WebFormHelper.php index fb0f1b2..d3fecfc 100644 --- a/inc/classes/main/helper/web/class_WebFormHelper.php +++ b/inc/classes/main/helper/web/class_WebFormHelper.php @@ -55,7 +55,7 @@ class WebFormHelper extends BaseHelper { const EXCEPTION_UNEXPECTED_CLOSED_GROUP = 0xb03; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/registry/.htaccess b/inc/classes/main/registry/.htaccess new file mode 100644 index 0000000..3a42882 --- /dev/null +++ b/inc/classes/main/registry/.htaccess @@ -0,0 +1 @@ +Deny from all diff --git a/inc/classes/main/registry/class_Registry.php b/inc/classes/main/registry/class_Registry.php new file mode 100644 index 0000000..8c69c2d --- /dev/null +++ b/inc/classes/main/registry/class_Registry.php @@ -0,0 +1,68 @@ + + * @version 0.3.0 + * @copyright Copyright(c) 2007, 2008 Roland Haeder, this is free software + * @license GNU GPL 3.0 or any newer version + * @link http://www.mxchange.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 Registry extends BaseFrameworkSystem { + /** + * Instance of this class + */ + private static $selfInstance = null; + + /** + * Protected constructor + * + * @return void + */ + protected function __construct () { + // Call parent constructor + parent::__construct(__CLASS__); + + // Set part description + $this->setObjectDescription("Registry class"); + + // Create unique ID number + $this->createUniqueID(); + + // Clean up a little + $this->removeNumberFormaters(); + $this->removeSystemArray(); + } + + /** + * Singleton getter for self instance + * + * @return $selfInstance Instance of this class + */ + public final static function getInstance () { + // Is an instance there? + if (is_null(self::$selfInstance)) { + // Not yet, so create one + self::$selfInstance = new Registry(); + } + + // Return the instance + return self::$selfInstance; + } +} + +// [EOF] +?> diff --git a/inc/classes/main/result/class_DatabaseResult.php b/inc/classes/main/result/class_DatabaseResult.php index 50f57e0..5214c1e 100644 --- a/inc/classes/main/result/class_DatabaseResult.php +++ b/inc/classes/main/result/class_DatabaseResult.php @@ -38,7 +38,7 @@ class DatabaseResult extends BaseFrameworkSystem { private $resultArray = array(); /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/main/user/class_User.php b/inc/classes/main/user/class_User.php index ad4498c..7d1d060 100644 --- a/inc/classes/main/user/class_User.php +++ b/inc/classes/main/user/class_User.php @@ -31,7 +31,7 @@ class User extends BaseFrameworkSystem implements ManageableUser { const EXCEPTION_USERNAME_NOT_FOUND = 0xd00; /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/middleware/class_BaseMiddleware.php b/inc/classes/middleware/class_BaseMiddleware.php index 6dc346b..3b64354 100644 --- a/inc/classes/middleware/class_BaseMiddleware.php +++ b/inc/classes/middleware/class_BaseMiddleware.php @@ -23,7 +23,7 @@ */ class BaseMiddleware extends BaseFrameworkSystem { /** - * Private constructor + * Protected constructor * * @return void */ diff --git a/inc/classes/middleware/compressor/class_CompressorChannel.php b/inc/classes/middleware/compressor/class_CompressorChannel.php index e48e091..7330515 100644 --- a/inc/classes/middleware/compressor/class_CompressorChannel.php +++ b/inc/classes/middleware/compressor/class_CompressorChannel.php @@ -22,10 +22,16 @@ * along with this program. If not, see . */ class CompressorChannel extends BaseMiddleware { - // Output handler instance + /** + * Real compressor instance + */ private $compressor = null; - // Public constructor + /** + * Protected constructor + * + * @return void + */ protected function __construct () { // Call parent constructor! parent::__construct(__CLASS__); @@ -37,7 +43,13 @@ class CompressorChannel extends BaseMiddleware { $this->createUniqueID(); } - // Create a new compressor channel based a given compression handler + /** + * Create a new compressor channel based a given base directory where + * we shall look for compressor classes + * + * @param $baseDir Directory which holds our compressor classes + * @return $cInstance A prepared instance of this class + */ public final static function createCompressorChannel ($baseDir) { // Get new instance $cInstance = new CompressorChannel(); diff --git a/inc/classes/middleware/debug/class_DebugMiddleware.php b/inc/classes/middleware/debug/class_DebugMiddleware.php index 02bbd63..9c73bd1 100644 --- a/inc/classes/middleware/debug/class_DebugMiddleware.php +++ b/inc/classes/middleware/debug/class_DebugMiddleware.php @@ -35,7 +35,7 @@ class DebugMiddleware extends BaseMiddleware { private static $thisInstance = null; /** - * Private constructor + * Protected constructor * * @return void */ -- 2.39.5