コード例 #1
0
ファイル: ArrayNodeTest.php プロジェクト: acappel01/opencall
 /**
  * Tests that no exception is thrown for an unrecognized child if the
  * ignoreExtraKeys option is set to true.
  *
  * Related to testExceptionThrownOnUnrecognizedChild
  */
 public function testIgnoreExtraKeysNoException()
 {
     $node = new ArrayNode('roo');
     $node->setIgnoreExtraKeys(true);
     $node->normalize(array('foo' => 'bar'));
     $this->assertTrue(true, 'No exception was thrown when setIgnoreExtraKeys is true');
 }
コード例 #2
0
ファイル: ArrayNodeTest.php プロジェクト: greggcz/librenms
 /**
  * Tests that extra keys are not removed when
  * ignoreExtraKeys second option is set to false.
  *
  * Related to testExceptionThrownOnUnrecognizedChild
  */
 public function testIgnoreExtraKeysNotRemoved()
 {
     $node = new ArrayNode('roo');
     $node->setIgnoreExtraKeys(true, false);
     $data = array('foo' => 'bar');
     $this->assertSame($data, $node->normalize($data));
 }
コード例 #3
0
ファイル: ArrayNodeTest.php プロジェクト: Ener-Getick/symfony
 /**
  * @dataProvider ignoreAndRemoveMatrixProvider
  */
 public function testIgnoreAndRemoveBehaviors($ignore, $remove, $expected, $message = '')
 {
     if ($expected instanceof \Exception) {
         $this->setExpectedException(get_class($expected), $expected->getMessage());
     }
     $node = new ArrayNode('root');
     $node->setIgnoreExtraKeys($ignore, $remove);
     $result = $node->normalize(array('foo' => 'bar'));
     $this->assertSame($expected, $result, $message);
 }
コード例 #4
0
ファイル: TreeBuilder.php プロジェクト: Gregwar/symfony
    /**
     * 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;
    }