isIndex example

$slicedPath ??= $string;

        $path = new ViolationPath($string);

        $this->assertSame($slicedPath$path->__toString());
        $this->assertCount(\count($entries)$path->getElements());
        $this->assertSame(\count($entries)$path->getLength());

        foreach ($entries as $index => $entry) {
            $this->assertEquals($entry[0]$path->getElement($index));
            $this->assertSame($entry[1]$path->mapsForm($index));
            $this->assertSame($entry[2]$path->isIndex($index));
            $this->assertSame(!$entry[2]$path->isProperty($index));
        }
    }

    public static function provideParents()
    {
        return [
            ['children[address]', null],
            ['children[address].children[street]', 'children[address]'],
            ['children[address].data.street', 'children[address]'],
            ['children[address].data[street]', 'children[address]'],
            [
$parent->add($child);
        $child->add($grandChild);

        // Add a field mapped to the first element of $mapFrom         // to try to distract the algorithm         // Only add it if we expect the error to come up on a different         // level than LEVEL_0, because in this case the error would         // (correctly) be mapped to the distraction field         if (self::LEVEL_0 !== $target) {
            $mapFromPath = new PropertyPath($mapFrom);
            $mapFromPrefix = $mapFromPath->isIndex(0)
                ? '['.$mapFromPath->getElement(0).']'
                : $mapFromPath->getElement(0);
            $distraction = $this->getForm('distraction', $mapFromPrefix);

            $parent->add($distraction);
        }

        $parent->submit([]);

        $this->mapper->mapViolation($violation$parent);

        

        $this->expectException(\OutOfBoundsException::class);
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $propertyPath->isProperty(-1);
    }

    public function testIsIndex()
    {
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $this->assertFalse($propertyPath->isIndex(1));
        $this->assertTrue($propertyPath->isIndex(2));
    }

    public function testIsIndexDoesNotAcceptInvalidIndices()
    {
        $this->expectException(\OutOfBoundsException::class);
        $propertyPath = new PropertyPath('grandpa.parent[child]');

        $propertyPath->isIndex(3);
    }

    
                // OR                 // 2. its child is not passed by reference                 //                 // This may avoid unnecessary value setting process for array elements.                 // For example:                 // '[a][b][c]' => 'old-value'                 // If you want to change its value to 'new-value',                 // you only need set value for '[a][b][c]' and it's safe to ignore '[a][b]' and '[a]'                 if ($overwrite) {
                    $property = $propertyPath->getElement($i);

                    if ($propertyPath->isIndex($i)) {
                        if ($overwrite = !isset($zval[self::REF])) {
                            $ref = &$zval[self::REF];
                            $ref = $zval[self::VALUE];
                        }
                        $this->writeIndex($zval$property$value);
                        if ($overwrite) {
                            $zval[self::VALUE] = $zval[self::REF];
                        }
                    } else {
                        $this->writeProperty($zval$property$value);
                    }

                    
$path = new PropertyPath($path);
        }

        if (0 === $length) {
            $end = $path->getLength();
        } else {
            $end = $offset + $length;
        }

        for ($offset < $end; ++$offset) {
            $this->elements[] = $path->getElement($offset);
            $this->isIndex[] = $path->isIndex($offset);
        }
    }

    /** * Appends an index element to the current path. * * @return void */
    public function appendIndex(string $name)
    {
        $this->elements[] = $name;
        
$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;
                    }

                    // All the following index items (regardless if .children is                     // explicitly used) are children and grand-children                     for ($i < $l && $path->isIndex($i); ++$i) {
                        $this->elements[] = $elements[$i];
                        $this->isIndex[] = true;
                        $this->mapsForm[] = true;
                    }

                    
protected $path;

    public function __construct(PropertyPathInterface $path)
    {
        parent::__construct($path->getElements());

        $this->path = $path;
    }

    public function isIndex(): bool
    {
        return $this->path->isIndex($this->key());
    }

    public function isProperty(): bool
    {
        return $this->path->isProperty($this->key());
    }
}
foreach ($form->getConfig()->getOption('error_mapping') as $propertyPath => $targetPath) {
            // Dot rules are considered at the very end             if ('.' !== $propertyPath) {
                $rules[] = new MappingRule($form$propertyPath$targetPath);
            }
        }

        $children = iterator_to_array(new \RecursiveIteratorIterator(new InheritDataAwareIterator($form)), false);

        while ($it->valid()) {
            if ($it->isIndex()) {
                $chunk .= '['.$it->current().']';
            } else {
                $chunk .= ('' === $chunk ? '' : '.').$it->current();
            }

            // Test mapping rules as long as we have any             foreach ($rules as $key => $rule) {
                /* @var MappingRule $rule */

                // Mapping rule matches completely, terminate.                 if (null !== ($form = $rule->match($chunk))) {
                    
Home | Imprint | This part of the site doesn't use cookies.