/** * @throws \InvalidArgumentException * @return bool */ public function evaluate() { if (!is_array($this->arguments)) { throw new \InvalidArgumentException("[any] constraint requires an array argument"); } if (!isset($this->arguments[0])) { $this->arguments = array($this->arguments); } $input = array($this->property => $this->data); foreach ($this->arguments as $key => $constraint_group) { if ($key === 'message') { $this->message = $constraint_group; continue; } $instance = new Validator($input, array('fields' => array($this->property => array_replace($this->inherit_schema, $constraint_group))), $this->validator); if ($instance->execute()) { $cleaned = $instance->getCleanedData(); if (isset($cleaned[$this->property])) { $this->cleaned = $cleaned[$this->property]; } return true; } else { $violations = $instance->getViolations(); $messages = array_intersect_key($violations[$this->property], array_flip(array('reason', 'message'))); if (!empty($messages)) { $this->violations[] = $messages; } } } return empty($this->violations); }
/** * @return bool */ public function evaluate() { $schema = array('fields' => array($this->property => $this->arguments)); foreach ($this->data as $i => $data) { $input = array($this->property => $data); $instance = new Validator($input, $schema, $this->validator); if ($instance->execute(true)) { $cleaned = $instance->getCleanedData(); $this->cleaned[$i] = $cleaned[$this->property]; } else { $violations = $instance->getViolations(); $this->violations = $violations[$this->property]; return false; } } return true; }
/** * Use the Wave Validator to check form input. If errors exist, the offending * values are inserted into $this->_input_errors. * * @param $schema - The validation schema for the Jade Validator * @param $data - [optional] Supply a data array to use for validation * @return Boolean true for no errors, or false. */ protected function inputValid($schema, $data = null) { if ($data === null) { $data = $this->_data; } try { $output = Validator::validate($schema, $data); $this->_cleaned = $output; return true; } catch (InvalidInputException $e) { $this->_input_errors = $e->getViolations(); } return false; }