コード例 #1
0
ファイル: ViolationPath.php プロジェクト: navassouza/symfony
 /**
  * Creates a new violation path from a string.
  *
  * @param string $violationPath The property path of a {@link ConstraintViolation}
  *                              object.
  */
 public function __construct($violationPath)
 {
     $path = new PropertyPath($violationPath);
     $elements = $path->getElements();
     $positions = $path->getPositions();
     $data = false;
     for ($i = 0, $l = count($elements); $i < $l; ++$i) {
         if (!$data) {
             // The element "data" has not yet been passed
             if ('children' === $elements[$i] && $path->isProperty($i)) {
                 // Skip element "children"
                 ++$i;
                 // Next element must exist and must be an index
                 // Otherwise consider this the end of the path
                 if ($i >= $l || !$path->isIndex($i)) {
                     break;
                 }
                 $this->elements[] = $elements[$i];
                 $this->positions[] = $positions[$i];
                 $this->isIndex[] = true;
                 $this->mapsForm[] = true;
             } elseif ('data' === $elements[$i] && $path->isProperty($i)) {
                 // Skip element "data"
                 ++$i;
                 // End of path
                 if ($i >= $l) {
                     break;
                 }
                 $this->elements[] = $elements[$i];
                 $this->positions[] = $positions[$i];
                 $this->isIndex[] = $path->isIndex($i);
                 $this->mapsForm[] = false;
                 $data = true;
             } else {
                 // Neither "children" nor "data" property found
                 // Consider this the end of the path
                 break;
             }
         } else {
             // Already after the "data" element
             // Pick everything as is
             $this->elements[] = $elements[$i];
             $this->positions[] = $positions[$i];
             $this->isIndex[] = $path->isIndex($i);
             $this->mapsForm[] = false;
         }
     }
     $this->length = count($this->elements);
     $this->pathAsString = $violationPath;
     $this->resizeString();
 }