示例#1
0
 public function testObjectFilterFail()
 {
     $name = '  Mathieu  ';
     $age = '  xyz  ';
     // invalid age
     $gender = '  B  ';
     // invalid gender
     $deceased = '';
     $person = new Person($name, $age, $gender, $deceased);
     $objectFilter = new ObjectFilter();
     $person = $objectFilter->filter($person);
     $this->assertNull($person);
     $this->assertTrue($objectFilter->hasMessages());
     $this->assertSame('The input is not a valid number', $objectFilter->getMessages()['age'][0]);
     $this->assertSame('The input content is not valid', $objectFilter->getMessages()['gender'][0]);
 }
示例#2
0
 private function validateRecursively(array $components = [])
 {
     foreach ($components as $component) {
         if ($component instanceof FieldSet) {
             $this->validateRecursively($component->getComponents());
         } else {
             $objectFilter = new ObjectFilter();
             $objectFilter->filter(clone $component);
             if ($objectFilter->hasMessages()) {
                 $errors = $objectFilter->getMessages();
                 $tmpErrors = [];
                 $componentName = $component->getPropertyName();
                 $tmpErrors[$componentName] = [];
                 foreach ($errors as $property => $messages) {
                     $component->addErrors($messages);
                     $tmpErrors[$componentName] = array_merge($tmpErrors[$componentName], $errors[$property]);
                 }
                 $this->messages = array_merge($this->messages, $tmpErrors);
             }
         }
     }
 }