*/
public static function normalize($str, $checkuse=false)
{
- if (mb_strlen($str) > self::MAX_LEN) {
- // Display forms must also fit!
- throw new NicknameTooLongException();
- }
-
+ // We should also have UTF-8 normalization (å to a etc.)
$str = trim($str);
$str = str_replace('_', '', $str);
$str = mb_strtolower($str);
- if (mb_strlen($str) < 1) {
+ if (mb_strlen($str) > self::MAX_LEN) {
+ // Display forms must also fit!
+ throw new NicknameTooLongException();
+ } elseif (mb_strlen($str) < 1) {
throw new NicknameEmptyException();
- }
- if (!self::isCanonical($str)) {
+ } elseif (!self::isCanonical($str)) {
throw new NicknameInvalidException();
- }
- if (self::isBlacklisted($str)) {
+ } elseif (self::isBlacklisted($str)) {
throw new NicknameBlacklistedException();
- }
- if (self::isSystemPath($str)) {
+ } elseif (self::isSystemPath($str)) {
throw new NicknamePathCollisionException();
- }
- if ($checkuse && $user = self::isTaken($str)) {
+ } elseif ($checkuse && $user = self::isTaken($str)) {
if ($user instanceof User) {
- throw new NicknameTakenException();
+ throw new NicknameTakenException($user);
}
}