public function testValidPropertyPath()
 {
     $path = new PropertyPath('reference.traversable[index].property');
     $this->assertEquals('reference', $path->getCurrent());
     $this->assertTrue($path->hasNext());
     $this->assertTrue($path->isProperty());
     $this->assertFalse($path->isIndex());
     $path->next();
     $this->assertEquals('traversable', $path->getCurrent());
     $this->assertTrue($path->hasNext());
     $this->assertTrue($path->isProperty());
     $this->assertFalse($path->isIndex());
     $path->next();
     $this->assertEquals('index', $path->getCurrent());
     $this->assertTrue($path->hasNext());
     $this->assertFalse($path->isProperty());
     $this->assertTrue($path->isIndex());
     $path->next();
     $this->assertEquals('property', $path->getCurrent());
     $this->assertFalse($path->hasNext());
     $this->assertTrue($path->isProperty());
     $this->assertFalse($path->isIndex());
 }
Exemple #2
0
 protected function updatePropertyPath(&$objectOrArray, PropertyPath $propertyPath)
 {
     if ($propertyPath->hasNext()) {
         if (is_object($objectOrArray)) {
             $value = $this->readProperty($objectOrArray, $propertyPath);
         } else {
             if (!array_key_exists($propertyPath->getCurrent(), $objectOrArray)) {
                 $objectOrArray[$propertyPath->getCurrent()] = array();
             }
             $value =& $objectOrArray[$propertyPath->getCurrent()];
         }
         $propertyPath->next();
         $this->updatePropertyPath($value, $propertyPath);
     } else {
         $this->updateProperty($objectOrArray, $propertyPath);
     }
 }
 /**
  * {@inheritDoc}
  */
 public function addError($message, PropertyPath $path = null, $type = null)
 {
     if ($path !== null) {
         if ($type === self::FIELD_ERROR && $path->hasNext()) {
             $path->next();
             if ($this->has($path->getCurrent()) && !$this->get($path->getCurrent())->isHidden()) {
                 $this->get($path->getCurrent())->addError($message, $path, $type);
                 return;
             }
         } else {
             if ($type === self::DATA_ERROR) {
                 $iterator = new RecursiveFieldsWithPropertyPathIterator($this);
                 $iterator = new \RecursiveIteratorIterator($iterator);
                 foreach ($iterator as $field) {
                     if (null !== ($fieldPath = $field->getPropertyPath())) {
                         $fieldPath->rewind();
                         if ($fieldPath->getCurrent() === $path->getCurrent() && !$field->isHidden()) {
                             if ($path->hasNext()) {
                                 $path->next();
                             }
                             $field->addError($message, $path, $type);
                             return;
                         }
                     }
                 }
             }
         }
     }
     parent::addError($message);
 }