public function __construct($model, $array, $message = 'Failed to validate array', array $values = NULL, $code = 0) { $this->model = $model; $this->array = $array; $errors = $array->errors(); //parent::__construct($array, $message, $values, $code); parent::__construct($message); }
/** * Валидация полей документа согласно правилам валидации * * @see DataSource_Document::rules() * @see DataSource_Document::labels() * * $doc = $ds->get_document($id); * $doc * ->read_values($this->request->post()) * ->read_files($_FILES) * ->validate($this->request->post() + $_FILES); * * @param Validation $extra_validation * @param array $expected * @return boolean|Validation */ public function validate(Validation $extra_validation = NULL, array $expected = NULL) { // Determine if any external validation failed $extra_errors = ($extra_validation and !$extra_validation->check()); // Default to expecting everything except the primary key if ($expected === NULL) { $fields = $this->section()->record()->fields(); $expected_rules = $this->rules(); } else { $fields = $this->section()->record()->fields(); foreach ($fields as $name => $field) { if (!in_array($field->id, $expected)) { unset($fields[$name]); } } $rules = $this->rules(); foreach ($rules as $field => $_rules) { if (!in_array($field, $expected)) { unset($rules[$field]); } } $expected_rules = $rules; } $values = $this->values(); $values['csrf'] = Arr::get($this->_temp_fields, 'csrf'); $validation = Validation::factory($values); $validation->rules('csrf', array(array('not_empty'), array('Security::check'))); foreach ($expected_rules as $field => $rules) { $validation->rules($field, $rules); } foreach ($this->labels() as $field => $label) { $validation->label($field, $label); } foreach ($fields as $name => $field) { $field->onValidateDocument($validation, $this); } if (!$validation->check() or $extra_errors) { $exception = new Validation_Exception($validation); if ($extra_errors) { // Merge any possible errors from the external object $exception->add_object($extra_validation); } throw $exception; } return TRUE; }
public function __construct($model, Validation $array, $message = 'Failed to validate array', array $values = NULL, $code = 0) { $this->model = $model; parent::__construct($array, $message, $values, $code); }