/** * {@inheritdoc} */ public function guard($value, Field $field) { Assertion::integer($value, null, $field->getName()); $intMin = $this->getMin(); $intMax = $this->getMax(); $min = NumberUtils::bound($field->getMin(), $intMin, $intMax); $max = NumberUtils::bound($field->getMax(), $intMin, $intMax); Assertion::range($value, $min, $max, null, $field->getName()); }
/** * {@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()); }
private function applyNumericOptions() { if (null !== $this->min) { if (null !== $this->max) { if ($this->min > $this->max) { $this->min = $this->max; } } } $this->precision = NumberUtils::bound($this->precision, 0, 65); // range 1-65 (we use 0 to ignore when generating class) $this->scale = NumberUtils::bound($this->scale, 0, $this->precision); }
/** * @param null|int $min * @param null|int $max * @param int $precision * @param int $scale */ private function applyNumericOptions($min = null, $max = null, $precision = 10, $scale = 2) { if (null !== $max) { $this->max = (int) $max; } if (null !== $min) { $this->min = (int) $min; if (null !== $this->max) { if ($this->min > $this->max) { $this->min = $this->max; } } } $this->precision = NumberUtils::bound((int) $precision, 1, 65); $this->scale = NumberUtils::bound((int) $scale, 0, $this->precision); }