]> git.mxchange.org Git - shipsimu.git/commitdiff
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 ec7d663a8ad782a38df83d89b4566512aa1bb910..056bd05426e2426b930b0fbe1d173b1b4e78ade9 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 03e03ef1dc96e973479da6fced3aa35aacd92df4..f23ae762621856fe7cbd2ed10f430e91085dccad 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 72790538e7b7125469e20f5b874f6929a2c30d79..a419393fb379cc4b97305fd579662c0bb39b63c7 100644 (file)
@@ -23,7 +23,7 @@
  */
 class WebShipsimuRegisterCommand extends BaseCommand implements Commandable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 7da2e1642835ec2a2a86f2ab3811d58dd6f88d8c..68a4122decd67a39273bca78cffa7b7958457a9c 100644 (file)
@@ -28,7 +28,7 @@ class MemoryCache extends BaseFrameworkSystem implements Cacheable {
        private $dataCache = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 9ffcf78b570e251022288df199e4272948c74861..8d46880e674f76986b6ffb1674d1983d557f5019 100644 (file)
@@ -23,7 +23,7 @@
  */
 class WebDoFormController extends BaseController implements Controller {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index a2f0910052abb4ba996be3001279fa964560942b..9d65fa8a3d70ac36cfb9d90d0799ade83ab99855 100644 (file)
@@ -40,7 +40,7 @@ class SearchCriteria extends BaseFrameworkSystem implements LocalCriteria {
        private $skip = 0;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 6133051540b7315978525a79864b22b1eee78524..9590b62a7e18b241c7c16df15535e64dd0120035 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 b212ccd5b47077358e9400ef36d9daf34a93a2c2..136c07b8fdec6092ff0958bbf341945fc02fea31 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 a9a1d4a66a46fde57ac4c377c705d5e1ddf7ccf8..025c3dee4f64a148399260d057b0e33c417f0161 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 cf2ff3b3c0fdb72c386fd1e2568c50ebde8c9365..cb1ac380aa740874030cb3bd8132014913481d6f 100644 (file)
@@ -28,7 +28,7 @@ class FilterChain extends BaseFrameworkSystem {
        private $filters = array();
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index 4b982b04b9b0b5aa30f0e429bb672875b33782da..a2f5628efc46c863d3d7f0c990cbd82728245ede 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 fab9eef5d04c20895eb4470e2556ae7740133153..cb82296417ac0c9536da564ace58fa199b84fcad 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 02a99e3aa16714b9eff08701e0eb95a01a2512c2..1a481944123ba035b703890ba8f77fdbedf82bc0 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 fb0f1b24d39d2784c6629e09dd06cb1648816d75..d3fecfc48f40545f8f29d0b1b06987f701933cb9 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 50f57e0675c503a643e56130d1b6b499ae8c8e6a..5214c1e603a28eb06497ddca325b91a8118881ee 100644 (file)
@@ -38,7 +38,7 @@ class DatabaseResult extends BaseFrameworkSystem {
        private $resultArray = array();
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index ad4498cb56db5dee9b704e27ea3b583b6bc709d5..7d1d060cdbb96207a8e816dfc740913d3ea9feb7 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 6dc346bd6f1a7e542bb38400a5fdabb7d45dd6f9..3b643540b54793c47c1d85ce4e86db91e7f43fe5 100644 (file)
@@ -23,7 +23,7 @@
  */
 class BaseMiddleware extends BaseFrameworkSystem {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
index e48e091a3784c2d201cc389c83953514896dada6..73305150e08c173a90a651dc81549f1ad6a20a4c 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 02bbd6350a87209dd66d0d79804942a487ca8486..9c73bd14d71ef851c07a592abef5a836c93e6c82 100644 (file)
@@ -35,7 +35,7 @@ class DebugMiddleware extends BaseMiddleware {
        private static $thisInstance = null;
 
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */