Registry introduces, comments fixed ;)
[shipsimu.git] / inc / classes / main / filter / validator / class_UserNameValidatorFilter.php
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;
                }