示例#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());
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function guard($value, Field $field)
 {
     /** @var Enum $value */
     Assertion::isInstanceOf($value, 'Gdbots\\Common\\Enum', null, $field->getName());
     Assertion::isInstanceOf($value, $field->getClassName(), null, $field->getName());
     $v = $value->getValue();
     Assertion::string($v, null, $field->getName());
     // intentionally using strlen to get byte length, not mb_strlen
     $length = strlen($v);
     $maxBytes = $this->getMaxBytes();
     $okay = $length > 0 && $length <= $maxBytes;
     Assertion::true($okay, sprintf('Field [%s] must be between [1] and [%d] bytes, [%d] bytes given.', $field->getName(), $maxBytes, $length), $field->getName());
 }