[Validator] added support for grapheme_strlen when mbstring is not installed but intl is installed
This commit is contained in:
parent
d429594afb
commit
600b8ef5af
@ -42,7 +42,13 @@ class MaxLengthValidator extends ConstraintValidator
|
||||
|
||||
$value = (string) $value;
|
||||
|
||||
$length = function_exists('mb_strlen') ? mb_strlen($value, $constraint->charset) : strlen($value);
|
||||
if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
|
||||
$length = grapheme_strlen($value);
|
||||
} elseif (function_exists('mb_strlen')) {
|
||||
$length = mb_strlen($value, $constraint->charset);
|
||||
} else {
|
||||
$length = strlen($value);
|
||||
}
|
||||
|
||||
if ($length > $constraint->limit) {
|
||||
$this->setMessage($constraint->message, array(
|
||||
|
@ -42,7 +42,13 @@ class MinLengthValidator extends ConstraintValidator
|
||||
|
||||
$value = (string) $value;
|
||||
|
||||
$length = function_exists('mb_strlen') ? mb_strlen($value, $constraint->charset) : strlen($value);
|
||||
if (function_exists('grapheme_strlen') && 'UTF-8' === $constraint->charset) {
|
||||
$length = grapheme_strlen($value);
|
||||
} elseif (function_exists('mb_strlen')) {
|
||||
$length = mb_strlen($value, $constraint->charset);
|
||||
} else {
|
||||
$length = strlen($value);
|
||||
}
|
||||
|
||||
if ($length < $constraint->limit) {
|
||||
$this->setMessage($constraint->message, array(
|
||||
|
Reference in New Issue
Block a user