/** * Construct an instance of a BetweenConstraint. * * @param int|float $min * @param int|float $max * * @throws LackOfCoffeeException * @throws InvalidArgumentException */ public function __construct($min, $max) { parent::__construct(); Arguments::define(new NumericConstraint(), new NumericConstraint())->check($min, $max); if ($min > $max) { throw new LackOfCoffeeException('Min should be smaller than or equal to max.'); } $this->min = $min; $this->max = $max; }
/** * Construct an instance of a StringLengthConstraint. * * @param int $min * @param int $max * * @throws InvalidArgumentException */ public function __construct($min = 0, $max = -1) { parent::__construct(); Arguments::define(Boa::integer(), Boa::integer())->check($min, $max); if ($min < 0) { throw new InvalidArgumentException('The minimum length is expected to be >= 0.'); } if ($max != -1 && $max < $min || $max < -1) { throw new InvalidArgumentException(' The maximum length is expected to be: (== -1 || >= minimum) &&' . ' >= -1.'); } $this->min = $min; $this->max = $max; }
/** * Construct an instance of a ClosureConstraint. * * @param Closure $closure * @param string|null $description */ public function __construct(Closure $closure, $description = null) { parent::__construct(); $this->closure = $closure; $this->description = Std::coalesce($description, 'The value is expected to meet the constraint.'); }
/** * Construct an instance of a ExactlyOneRecordConstraint. * * @param Builder $query * @param array $where */ public function __construct(Builder $query, array $where = []) { parent::__construct(); $this->query = $query; $this->where = $where; }
/** * Construct an instance of a AtLeastOneOfConstraint. * * @param array $fields */ public function __construct(array $fields) { parent::__construct(); Arguments::define(Boa::arrOf(Boa::string()))->check($fields); $this->fields = $fields; }
/** * Construct an instance of a RegexConstraint. * * @param string $pattern */ public function __construct($pattern) { parent::__construct(); $this->pattern = $pattern; }