1 | <?php |
||
19 | class EntityValidator |
||
20 | { |
||
21 | |||
22 | /** |
||
23 | * The entity to validate. |
||
24 | * @var Entity |
||
25 | */ |
||
26 | protected $entity; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * The entities definition. |
||
31 | * @var EntityDefinition |
||
32 | */ |
||
33 | protected $definition; |
||
34 | |||
35 | |||
36 | /** |
||
37 | * Builds up the validation rules for a single field according to the |
||
38 | * entity definition type. |
||
39 | * |
||
40 | * @param string $field |
||
41 | * the field for the rules |
||
42 | * @param AbstractData $data |
||
43 | * the data instance to use for validation |
||
44 | * @param Validator $validator |
||
45 | * the validator to use |
||
46 | * |
||
47 | * @return array |
||
48 | * the validation rules for the field |
||
49 | */ |
||
50 | 5 | protected function fieldTypeToRules($field, AbstractData $data, Validator $validator) |
|
70 | |||
71 | |||
72 | /** |
||
73 | * Builds up the validation rules for a single field according to the |
||
74 | * entity definition constraints. |
||
75 | * |
||
76 | * @param string $field |
||
77 | * the field for the rules |
||
78 | * @param AbstractData $data |
||
79 | * the data instance to use for validation |
||
80 | * |
||
81 | * @return array |
||
82 | * the validation rules for the field |
||
83 | */ |
||
84 | 5 | protected function fieldConstraintsToRules($field, AbstractData $data) |
|
95 | |||
96 | |||
97 | /** |
||
98 | * Builds up the validation rules for the entity according to its |
||
99 | * definition. |
||
100 | * @param AbstractData $data |
||
101 | * the data instance to use for validation |
||
102 | * @param Validator $validator |
||
103 | * the validator to use |
||
104 | * |
||
105 | * @return array |
||
106 | * the validation rules for the entity |
||
107 | */ |
||
108 | 5 | protected function buildUpRules(AbstractData $data, Validator $validator) |
|
121 | |||
122 | |||
123 | /** |
||
124 | * Builds up the data to validate from the entity. |
||
125 | * |
||
126 | * @return array |
||
127 | * a map field to raw value |
||
128 | */ |
||
129 | 5 | protected function buildUpData() |
|
147 | |||
148 | |||
149 | /** |
||
150 | * Constructor. |
||
151 | * |
||
152 | * @param Entity $entity |
||
153 | * the entity to validate |
||
154 | */ |
||
155 | 5 | public function __construct(Entity $entity) |
|
160 | |||
161 | |||
162 | /** |
||
163 | * Validates the entity against the definition. |
||
164 | * |
||
165 | * @param AbstractData $data |
||
166 | * the data access instance used for counting things |
||
167 | * @param integer $expectedVersion |
||
168 | * the version to perform the optimistic locking check on |
||
169 | * |
||
170 | * @return array |
||
|
|||
171 | * an array with the fields "valid" and "errors"; valid provides a quick |
||
172 | * check whether the given entity passes the validation and errors is an |
||
173 | * array with all errored fields as keys and arrays as values; this field arrays |
||
174 | * contains the actual errors on the field: "boolean", "floating", "integer", |
||
175 | * "dateTime" (for dates and datetime fields), "inSet", "reference", "required", |
||
176 | * "unique", "value" (only for the version field, set if the optimistic locking |
||
177 | * failed). |
||
178 | */ |
||
179 | 5 | public function validate(AbstractData $data, $expectedVersion) |
|
194 | |||
195 | } |
||
196 |
This check looks for the generic type
array
as a return type and suggests a more specific type. This type is inferred from the actual code.