Ejemplo n.º 1
0
    /**
     * Creates an array node.
     *
     * @param NodeBuilder $node The builder of the node
     *
     * @return Symfony\Component\Config\Definition\ArrayNode
     */
    protected function createArrayConfigNode(NodeBuilder $node)
    {
        $configNode = new ArrayNode($node->name, $node->parent);
        $configNode->setAddIfNotSet($node->addDefaults);
        $configNode->setAllowNewKeys($node->allowNewKeys);
        $configNode->addEquivalentValue(null, $node->nullEquivalent);
        $configNode->addEquivalentValue(true, $node->trueEquivalent);
        $configNode->addEquivalentValue(false, $node->falseEquivalent);
        $configNode->setPerformDeepMerging($node->performDeepMerging);
        $configNode->setRequired($node->required);
        $configNode->setIgnoreExtraKeys($node->ignoreExtraKeys);

        if (null !== $node->key) {
            $configNode->setKeyAttribute($node->key, $node->removeKeyItem);
        }

        if (true === $node->atLeastOne) {
            $configNode->setMinNumberOfElements(1);
        }

        if (null !== $node->normalization) {
            $configNode->setNormalizationClosures(
                $this->buildExpressions($node->normalization->before)
            );

            $configNode->setXmlRemappings($node->normalization->remappings);
        }

        if (null !== $node->merge) {
            $configNode->setAllowOverwrite($node->merge->allowOverwrite);
            $configNode->setAllowFalse($node->merge->allowFalse);
        }

        foreach ($node->children as $child) {
            $child->parent = $configNode;

            $configNode->addChild($this->createConfigNode($child));
        }

        if (null !== $node->prototype) {
            $node->prototype->parent = $configNode;
            $configNode->setPrototype($this->createConfigNode($node->prototype));
        }

        if (null !== $node->defaultValue) {
            $configNode->setDefaultValue($node->defaultValue);
        }

        if (null !== $node->validation) {
            $configNode->setFinalValidationClosures(
                $this->buildExpressions($node->validation->rules)
            );
        }

        return $configNode;
    }
Ejemplo n.º 2
0
 /**
  * Tests the opposite of the testMappedAttributeKeyIsRemoved because
  * the removal can be toggled with an option.
  */
 public function testMappedAttributeKeyNotRemoved()
 {
     $node = new ArrayNode('root');
     $node->setKeyAttribute('id', false);
     // each item under the root is an array, with two scalar items
     $prototype = new ArrayNode(null, $node);
     $prototype->addChild(new ScalarNode('foo'));
     $prototype->addChild(new ScalarNode('id'));
     // the key attribute will remain
     $node->setPrototype($prototype);
     $children = array();
     $children[] = array('id' => 'item_name', 'foo' => 'bar');
     $normalized = $node->normalize($children);
     $expected = array();
     $expected['item_name'] = array('id' => 'item_name', 'foo' => 'bar');
     $this->assertEquals($expected, $normalized);
 }