]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
Registry introduces, comments fixed ;)
[shipsimu.git] / inc / classes / main / filter / validator / class_UserNameValidatorFilter.php
index 1c7c54afc820da98a0e2332fafd82737f416aa5a..cb82296417ac0c9536da564ace58fa199b84fcad 100644 (file)
@@ -26,7 +26,7 @@
  */
 class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
@@ -74,7 +74,7 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                        // Not found in form so stop the filtering process
                        $requestInstance->requestIsValid(false);
 
-                       // Set a message for the response
+                       // Add a message to the response
                        $responseInstance->addFatalMessage('username_unset');
 
                        // Abort here
@@ -83,7 +83,7 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                        // Empty field!
                        $requestInstance->requestIsValid(false);
 
-                       // Set a message for the response
+                       // Add a message to the response
                        $responseInstance->addFatalMessage('username_empty');
 
                        // Abort here
@@ -92,7 +92,7 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                        // Username is already taken
                        $requestInstance->requestIsValid(false);
 
-                       // Set a message for the response
+                       // Add a message to the response
                        $responseInstance->addFatalMessage('username_taken');
 
                        // Abort here
@@ -110,16 +110,25 @@ 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;
-               } catch (FrameworkException $e) {
-                       // Something bad happend
-                       ApplicationEntryPoint::app_die(sprintf("Exception: %s", $e->__toString()));
                }
 
                // Return the result