Skip to content

Commit

Permalink
[Validator] drop grapheme_strlen in LengthValidator
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jan 26, 2015
1 parent 975b8a8 commit 915fcd8
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/Symfony/Component/Validator/Constraints/LengthValidator.php
Expand Up @@ -35,12 +35,20 @@ public function validate($value, Constraint $constraint)

$stringValue = (string) $value;

if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
$length = grapheme_strlen($stringValue);
if ('UTF8' === $charset = strtoupper($constraint->charset)) {
$charset = 'UTF-8';
}

if (function_exists('iconv_strlen')) {
$length = iconv_strlen($stringValue, $constraint->charset);
} elseif (function_exists('mb_strlen')) {
$length = mb_strlen($stringValue, $constraint->charset);
} else {
} elseif ('UTF-8' !== $charset) {
$length = strlen($stringValue);
} elseif (function_exists('utf8_decode')) {
$length = strlen(utf8_decode($stringValue));
} else {
preg_replace('/./u', '', $stringValue, -1, $length);
}

if ($constraint->min == $constraint->max && $length != $constraint->min) {
Expand Down

0 comments on commit 915fcd8

Please sign in to comment.