| @@ 14-85 (lines=72) @@ | ||
| 11 | use Weew\Validator\Constraints\MinLengthConstraint; |
|
| 12 | use Weew\Validator\Constraints\NotNullConstraint; |
|
| 13 | ||
| 14 | class ArrayNode extends Node implements IArrayNode { |
|
| 15 | /** |
|
| 16 | * ArrayNode constructor. |
|
| 17 | * |
|
| 18 | * @param IConfigSchema $schema |
|
| 19 | * @param string $key |
|
| 20 | * @param string $message |
|
| 21 | */ |
|
| 22 | public function __construct(IConfigSchema $schema, $key, $message = null) { |
|
| 23 | parent::__construct($schema, $key); |
|
| 24 | ||
| 25 | $this->constraints([ |
|
| 26 | new NotNullConstraint($message), |
|
| 27 | new ArrayConstraint(), |
|
| 28 | ]); |
|
| 29 | } |
|
| 30 | ||
| 31 | /** |
|
| 32 | * @param int $min |
|
| 33 | * |
|
| 34 | * @return IArrayNode |
|
| 35 | */ |
|
| 36 | public function min($min) { |
|
| 37 | return $this->constraint( |
|
| 38 | new MinLengthConstraint($min) |
|
| 39 | ); |
|
| 40 | } |
|
| 41 | ||
| 42 | /** |
|
| 43 | * @param int $max |
|
| 44 | * |
|
| 45 | * @return IArrayNode |
|
| 46 | */ |
|
| 47 | public function max($max) { |
|
| 48 | return $this->constraint( |
|
| 49 | new MaxLengthConstraint($max) |
|
| 50 | ); |
|
| 51 | } |
|
| 52 | ||
| 53 | /** |
|
| 54 | * @param int $length |
|
| 55 | * |
|
| 56 | * @return IArrayNode |
|
| 57 | */ |
|
| 58 | public function length($length) { |
|
| 59 | return $this->constraint( |
|
| 60 | new LengthConstraint($length) |
|
| 61 | ); |
|
| 62 | } |
|
| 63 | ||
| 64 | /** |
|
| 65 | * @param array $values |
|
| 66 | * |
|
| 67 | * @return IArrayNode |
|
| 68 | */ |
|
| 69 | public function allowed(array $values) { |
|
| 70 | return $this->constraint( |
|
| 71 | new AllowedSubsetConstraint($values) |
|
| 72 | ); |
|
| 73 | } |
|
| 74 | ||
| 75 | /** |
|
| 76 | * @param array $values |
|
| 77 | * |
|
| 78 | * @return IArrayNode |
|
| 79 | */ |
|
| 80 | public function forbidden(array $values) { |
|
| 81 | return $this->constraint( |
|
| 82 | new ForbiddenSubsetConstraint($values) |
|
| 83 | ); |
|
| 84 | } |
|
| 85 | } |
|
| 86 | ||
| @@ 13-73 (lines=61) @@ | ||
| 10 | use Weew\Validator\Constraints\NotNullConstraint; |
|
| 11 | use Weew\Validator\Constraints\NumericConstraint; |
|
| 12 | ||
| 13 | class NumericNode extends Node implements INumericNode { |
|
| 14 | /** |
|
| 15 | * NumericNode constructor. |
|
| 16 | * |
|
| 17 | * @param IConfigSchema $schema |
|
| 18 | * @param string $key |
|
| 19 | * @param string $message |
|
| 20 | */ |
|
| 21 | public function __construct(IConfigSchema $schema, $key, $message = null) { |
|
| 22 | parent::__construct($schema, $key); |
|
| 23 | ||
| 24 | $this->constraints([ |
|
| 25 | new NotNullConstraint($message), |
|
| 26 | new NumericConstraint(), |
|
| 27 | ]); |
|
| 28 | } |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @param int $min |
|
| 32 | * |
|
| 33 | * @return INumericNode |
|
| 34 | */ |
|
| 35 | public function min($min) { |
|
| 36 | return $this->constraint( |
|
| 37 | new MinConstraint($min) |
|
| 38 | ); |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * @param int $max |
|
| 43 | * |
|
| 44 | * @return INumericNode |
|
| 45 | */ |
|
| 46 | public function max($max) { |
|
| 47 | return $this->constraint( |
|
| 48 | new MaxConstraint($max) |
|
| 49 | ); |
|
| 50 | } |
|
| 51 | ||
| 52 | /** |
|
| 53 | * @param array $values |
|
| 54 | * |
|
| 55 | * @return INumericNode |
|
| 56 | */ |
|
| 57 | public function allowed(array $values) { |
|
| 58 | return $this->constraint( |
|
| 59 | new AllowedConstraint($values) |
|
| 60 | ); |
|
| 61 | } |
|
| 62 | ||
| 63 | /** |
|
| 64 | * @param array $values |
|
| 65 | * |
|
| 66 | * @return INumericNode |
|
| 67 | */ |
|
| 68 | public function forbidden(array $values) { |
|
| 69 | return $this->constraint( |
|
| 70 | new ForbiddenConstraint($values) |
|
| 71 | ); |
|
| 72 | } |
|
| 73 | } |
|
| 74 | ||