Example #1
0
 private function validateMap($value)
 {
     $errors = array();
     if ($this->options['map'] instanceof ValidatorInterface) {
         $this->options['map'] = array($this->options['map'], 'validate');
     }
     if (!is_callable($this->options['map'])) {
         throw new \InvalidArgumentException('Parameter "map" is not callable.');
     }
     $propertiesErrors = array_map($this->options['map'], $value);
     if ($propertiesErrors) {
         foreach ($propertiesErrors as $key => $propertyErrors) {
             if (!is_array($propertyErrors)) {
                 $propertyErrors = array($propertyErrors);
             }
             foreach ($propertyErrors as $propertyError) {
                 if ($propertyError instanceof Error) {
                     $propertyError = new PropertyError($propertyError->getText(), $key);
                     $errors[] = $propertyError;
                 } elseif ($propertyError instanceof PropertyError) {
                     $propertyError->prependPath($key);
                     $errors[] = $propertyError;
                 } elseif ($propertyError !== null) {
                     $propertyError = new PropertyError($propertyError, $key);
                     $errors[] = $propertyError;
                 }
             }
         }
     }
     return $errors;
 }
 /**
  * @covers Yosmanyga\Validation\Validator\Error\PropertyError::prependPath
  */
 public function testPrependPath()
 {
     $error = new PropertyError('', 'p1');
     $error->prependPath('p2');
     $this->assertEquals('p2.p1', $error->getPath());
 }