]> git.mxchange.org Git - shipsimu.git/blobdiff - inc/classes/main/filter/validator/class_UserNameValidatorFilter.php
A lot more old methods deprecated and already deprecated methods removed
[shipsimu.git] / inc / classes / main / filter / validator / class_UserNameValidatorFilter.php
index fab9eef5d04c20895eb4470e2556ae7740133153..456f16a40c0933e68c3f67b49914e6d5876d59e2 100644 (file)
@@ -24,9 +24,9 @@
  * 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 UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable {
+class UserNameValidatorFilter extends BaseFilter implements Filterable {
        /**
-        * Private constructor
+        * Protected constructor
         *
         * @return      void
         */
@@ -38,11 +38,7 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                $this->setObjectDescription("A filter for username validation");
 
                // Create unique ID number
-               $this->createUniqueID();
-
-               // Clean up a little
-               $this->removeNumberFormaters();
-               $this->removeSystemArray();
+               $this->generateUniqueId();
        }
 
        /**
@@ -110,12 +106,33 @@ class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable
                // Default is already taken
                $alreadyTaken = true;
 
-               // Try to create a user instance
-               try {
+               // Initialize instance
+               $userInstance = null;
+
+               // Get a registry instance
+               $registry = Registry::getRegistry();
+
+               // Is the user already there?
+               if ($registry->instanceExists('user')) {
+                       // Use the instance for checking for the email
+                       $userInstance = $registry->getInstance('user');
+                       $userInstance->setUserName($userName);
+               } else {
                        // If this instance is created then the username *does* exist
-                       $userInstance = User::createUserByUsername($userName);
-               } catch (UsernameMissingException $e) {
-                       // Okay, this user is missing!
+                       try {
+                               // Get a new instance
+                               $userInstance = call_user_func_array(array($this->getConfigInstance()->readConfig('user_class'), "createUserByUsername"), array($userName));
+
+                               // Remember this user instance in our registry for later usage
+                               $registry->addInstance('user', $userInstance);
+                       } catch (UsernameMissingException $e) {
+                               // User was not found
+                       }
+               }
+
+               // Does the username exist?
+               if ((is_null($userInstance)) || (!$userInstance->ifUsernameExists())) {
+                       // This username is still available
                        $alreadyTaken = false;
                }