1 | <?php |
||
29 | class Validator |
||
30 | { |
||
31 | /** |
||
32 | * @var array Associative array of field name to list of rules |
||
33 | */ |
||
34 | protected $ruleset; |
||
35 | |||
36 | /** |
||
37 | * Creates a new validator. |
||
38 | * |
||
39 | * @param array $ruleset Associative array of field name to list of rules |
||
40 | 1 | */ |
|
41 | public function __construct(array $ruleset) |
||
45 | |||
46 | /** |
||
47 | * Gets a field from the values. |
||
48 | * |
||
49 | * This can be overridden to access by other means (e.g. object properties, |
||
50 | * getter methods). |
||
51 | * |
||
52 | * @param mixed $values The values |
||
53 | * @param string $field The field to access |
||
54 | * @return mixed The accessed value |
||
55 | 1 | */ |
|
56 | protected function access($values, string $field) |
||
60 | |||
61 | /** |
||
62 | * Iterates over the ruleset and collects any error codes. |
||
63 | * |
||
64 | * @param object|array $values An object or associative array to validate |
||
65 | * @return array Associative array of field name to error |
||
66 | * @throws \InvalidArgumentException if `$values` is null |
||
67 | 2 | */ |
|
68 | protected function iterate($values) |
||
91 | |||
92 | /** |
||
93 | * Validates the provided value, returning a result object. |
||
94 | * |
||
95 | 1 | * @param object|array $values An object or associative array to validate |
|
96 | * @return \Caridea\Validate\Result The validation results |
||
97 | 1 | * @throws \InvalidArgumentException if `$values` is null |
|
98 | */ |
||
99 | public function validate($values): Result |
||
103 | |||
104 | /** |
||
105 | * Validates the provided value, throwing an exception upon failure. |
||
106 | * |
||
107 | 2 | * @param object|array $values An object or associative array to validate |
|
108 | * @throws \Caridea\Validate\Exception\Invalid if validation fails |
||
109 | 2 | * @throws \InvalidArgumentException if `$values` is null |
|
110 | 2 | */ |
|
111 | 1 | public function assert($values) |
|
118 | } |
||
119 |