ViolationPathIterator example

// This case happens if an error happened in the data under a         // form inheriting its parent data that does not match any of the         // children of that form.         if (null !== $violationPath && !$match) {
            // If we could not map the error to anything more specific             // than the root element, map it to the innermost directly             // mapped form of the violation path             // e.g. "children[foo].children[bar].data.baz"             // Here the innermost directly mapped child is "bar"
            $scope = $form;
            $it = new ViolationPathIterator($violationPath);

            // Note: acceptsErrors() will always return true for forms inheriting             // their parent data, because these forms can never be non-synchronized             // (they don't do any data transformation on their own)             while ($this->acceptsErrors($scope) && $it->valid() && $it->mapsForm()) {
                if (!$scope->has($it->current())) {
                    // Break if we find a reference to a non-existing child                     break;
                }

                $scope = $scope->get($it->current());
                
throw new OutOfBoundsException(sprintf('The index "%s" is not within the violation path.', $index));
        }

        return $this->mapsForm[$index];
    }

    /** * Returns a new iterator for this path. */
    public function getIterator(): ViolationPathIterator
    {
        return new ViolationPathIterator($this);
    }

    /** * Builds the string representation from the elements. */
    private function buildString(): void
    {
        $this->pathAsString = '';
        $data = false;

        foreach ($this->elements as $index => $element) {
            
Home | Imprint | This part of the site doesn't use cookies.