Symfony2 tree creator - what does the canBeUnset () method do?

$rootNode
    ->children()
        ->arrayNode('form')
            ->info('form configuration')
            ->canBeUnset()
            ->treatNullLike(array('enabled' => true))
            ->treatTrueLike(array('enabled' => true))
            ->children()
                ->booleanNode('enabled')->defaultTrue()->end()
            ->end()
        ->end()

Line 5 of the above snippet from Symfony\Bundle\FrameworkBundle\DependencyInjection\Configurationuses the method canBeUnset(). I do not know what this does, because it does not do anything if I delete it. I am working on understanding the semantic configuration for my own packages.

+5
source share
1 answer

Following the code, you can find the definition for this method in the class Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.

/**
 * Sets whether the node can be unset.
 *
 * @param Boolean $allow
 *
 * @return ArrayNodeDefinition
 */
public function canBeUnset($allow = true)
{
    $this->merge()->allowUnset($allow);

    return $this;
}

This is passed to MergeBuilder ( Symfony/Component/Config/Definition/Builder/MergeBuilder), which handles merging configurations.

/**
 * Sets whether the node can be unset.
 *
 * @param Boolean $allow
 *
 * @return MergeBuilder
 */
public function allowUnset($allow = true)
{
    $this->allowFalse = $allow;

    return $this;
}

, , , , . , , , , , - , isRequired.

+6

All Articles