Ejemplo n.º 1
0
 /**
  * @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);
 }
Ejemplo n.º 2
0
 /**
  * @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;
 }