Example #1
0
 /**
  * {@inheritdoc}
  */
 public function guard($value, Field $field)
 {
     Assertion::string($value, null, $field->getName());
     // intentionally using strlen to get byte length, not mb_strlen
     $length = strlen($value);
     $minLength = $field->getMinLength();
     $maxLength = NumberUtils::bound($field->getMaxLength(), $minLength, $this->getMaxBytes());
     $okay = $length >= $minLength && $length <= $maxLength;
     Assertion::true($okay, sprintf('Field [%s] must be between [%d] and [%d] bytes, [%d] bytes given.', $field->getName(), $minLength, $maxLength, $length), $field->getName());
 }