setAddIfNotSet example

return $this->nodeBuilder->setParent($this);
    }

    protected function createNode(): NodeInterface
    {
        if (!isset($this->prototype)) {
            $node = new ArrayNode($this->name, $this->parent, $this->pathSeparator);

            $this->validateConcreteNode($node);

            $node->setAddIfNotSet($this->addDefaults);

            foreach ($this->children as $child) {
                $child->parent = $node;
                $node->addChild($child->getNode());
            }
        } else {
            $node = new PrototypedArrayNode($this->name, $this->parent, $this->pathSeparator);

            $this->validatePrototypeNode($node);

            if (null !== $this->key) {
                
$this->assertTrue($node->hasDefaultValue());
        $this->assertEquals([['foo' => 'bar']]$node->getDefaultValue());
    }

    protected function getPrototypeNodeWithDefaultChildren()
    {
        $node = new PrototypedArrayNode('root');
        $prototype = new ArrayNode(null, $node);
        $child = new ScalarNode('foo');
        $child->setDefaultValue('bar');
        $prototype->addChild($child);
        $prototype->setAddIfNotSet(true);
        $node->setPrototype($prototype);

        return $node;
    }

    /** * Tests that when a key attribute is mapped, that key is removed from the array. * And if only 'value' element is left in the array, it will replace its wrapper array. * * <things> * <option id="option1" value="value1"> * </things> * * The above should finally be mapped to an array that looks like this * (because "id" is the key attribute). * * [ * 'things' => [ * 'option1' => 'value1' * ] * ] * * It's also possible to mix 'value-only' and 'non-value-only' elements in the array. * * <things> * <option id="option1" value="value1"> * <option id="option2" value="value2" foo="foo2"> * </things> * * The above should finally be mapped to an array as follows * * [ * 'things' => [ * 'option1' => 'value1', * 'option2' => [ * 'value' => 'value2', * 'foo' => 'foo2' * ] * ] * ] * * The 'value' element can also be ArrayNode: * * <things> * <option id="option1"> * <value> * <foo>foo1</foo> * <bar>bar1</bar> * </value> * </option> * </things> * * The above should be finally be mapped to an array as follows * * [ * 'things' => [ * 'option1' => [ * 'foo' => 'foo1', * 'bar' => 'bar1' * ] * ] * ] * * If using VariableNode for value node, it's also possible to mix different types of value nodes: * * <things> * <option id="option1"> * <value> * <foo>foo1</foo> * <bar>bar1</bar> * </value> * </option> * <option id="option2" value="value2"> * </things> * * The above should be finally mapped to an array as follows * * [ * 'things' => [ * 'option1' => [ * 'foo' => 'foo1', * 'bar' => 'bar1' * ], * 'option2' => 'value2' * ] * ] * * @dataProvider getDataForKeyRemovedLeftValueOnly */
Home | Imprint | This part of the site doesn't use cookies.