Registry introduces, comments fixed ;)
authorRoland Häder <roland@mxchange.org>
Mon, 2 Jun 2008 17:27:16 +0000 (17:27 +0000)
committerRoland Häder <roland@mxchange.org>
Mon, 2 Jun 2008 17:27:16 +0000 (17:27 +0000)
21 files changed:
.gitattributes
application/selector/class_ApplicationSelector.php
application/ship-simu/main/commands/web/class_WebShipsimuRegisterCommand.php
inc/classes/main/cache/class_MemoryCache.php
inc/classes/main/controller/form/class_WebDoFormController.php
inc/classes/main/criteria/class_SearchCriteria.php
inc/classes/main/database/databases/class_LocalFileDatabase.php
inc/classes/main/extended/class_SerializationContainer.php
inc/classes/main/filter/class_AbstractFilterDecorator.php
inc/classes/main/filter/class_FilterChain.php
inc/classes/main/filter/validator/class_EmailValidatorFilter.php
inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
inc/classes/main/helper/class_BaseHelper.php
inc/classes/main/helper/web/class_WebFormHelper.php
inc/classes/main/registry/.htaccess [new file with mode: 0644]
inc/classes/main/registry/class_Registry.php [new file with mode: 0644]
inc/classes/main/result/class_DatabaseResult.php
inc/classes/main/user/class_User.php
inc/classes/middleware/class_BaseMiddleware.php
inc/classes/middleware/compressor/class_CompressorChannel.php
inc/classes/middleware/debug/class_DebugMiddleware.php

index ec7d663..056bd05 100644 (file)
@@ -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
index 03e03ef..f23ae76 100644 (file)
@@ -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
         */
index 7279053..a419393 100644 (file)
@@ -23,7 +23,7 @@
  */
 class WebShipsimuRegisterCommand extends BaseCommand implements Commandable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 7da2e16..68a4122 100644 (file)
@@ -28,7 +28,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
        private $dataCache = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 9ffcf78..8d46880 100644 (file)
@@ -23,7 +23,7 @@
  */
 class WebDoFormController extends BaseController implements Controller {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index a2f0910..9d65fa8 100644 (file)
@@ -40,7 +40,7 @@ class SearchCriteria extends BaseFrameworkSystem implements LocalCriteria {
        private $skip = 0;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 6133051..9590b62 100644 (file)
@@ -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
         */
index b212ccd..136c07b 100644 (file)
  */
 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) {
index a9a1d4a..025c3de 100644 (file)
@@ -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
index cf2ff3b..cb1ac38 100644 (file)
@@ -28,7 +28,7 @@ class FilterChain extends BaseFrameworkSystem {
        private $filters = array();
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 4b982b0..a2f5628 100644 (file)
@@ -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;
index fab9eef..cb82296 100644 (file)
@@ -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;
                }
 
index 02a99e3..1a48194 100644 (file)
@@ -33,7 +33,7 @@ class BaseHelper extends BaseFrameworkSystem {
        private $content = "";
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @param       $className      Real name of the class
         * @return      void
index fb0f1b2..d3fecfc 100644 (file)
@@ -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 (file)
index 0000000..3a42882
--- /dev/null
@@ -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 (file)
index 0000000..8c69c2d
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+/**
+ * A registry for several data types
+ *
+ * @author             Roland Haeder <webmaster@ship-simu.org>
+ * @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 <http://www.gnu.org/licenses/>.
+ */
+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]
+?>
index 50f57e0..5214c1e 100644 (file)
@@ -38,7 +38,7 @@ class DatabaseResult extends BaseFrameworkSystem {
        private $resultArray = array();
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index ad4498c..7d1d060 100644 (file)
@@ -31,7 +31,7 @@ class User extends BaseFrameworkSystem implements ManageableUser {
        const EXCEPTION_USERNAME_NOT_FOUND = 0xd00;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 6dc346b..3b64354 100644 (file)
@@ -23,7 +23,7 @@
  */
 class BaseMiddleware extends BaseFrameworkSystem {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index e48e091..7330515 100644 (file)
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 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();
index 02bbd63..9c73bd1 100644 (file)
@@ -35,7 +35,7 @@ class DebugMiddleware extends BaseMiddleware {
        private static $thisInstance = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */