/** * @param $result Results\Result * @param $value array * @return array */ public function validateData($result, $value) { $count = count($value); $min = $this->minCount; $max = $this->maxCount; if ($min !== null && $count < $min || $max !== null && $count > $max) { $result->addItemCountError($count, $min, $max); } if ($this->itemRule === null && $this->keyRule === null) { return array(); } foreach ($value as $key => $item) { $itemResult = $result->field($key); if ($this->keyRule !== null) { $this->keyRule->validate($key, $itemResult); } if ($this->itemRule !== null) { $this->itemRule->validate($item, $itemResult); } } }
/** * @param $value array|object * @return Results\Result\Root */ public function validate($value) { $result = $this->results->root($value); $this->rule->validate($value, $result); return $result; }