*/
class UserNameValidatorFilter extends BaseFrameworkSystem implements Filterable {
/**
- * Private constructor
+ * Protected constructor
*
* @return void
*/
// 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;
}