Class

Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition

class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinitionInterface

This class provides a fluent interface for defining an array node.

Methods

__construct(string $name, NodeParentInterface $parent = null)

Constructor

NodeDefinition setParent(NodeParentInterface $parent)

Sets the parent node.

from NodeDefinition
NodeDefinition info(string $info)

Sets info message.

from NodeDefinition
NodeDefinition example(string|array $example)

Sets example configuration.

from NodeDefinition
NodeDefinition attribute(string $key, mixed $value)

Sets an attribute on the node.

from NodeDefinition
NodeParentInterface end()

Returns the parent node.

from NodeDefinition
NodeInterface getNode(Boolean $forceRootNode = false)

Creates the node.

from NodeDefinition
NodeDefinition defaultValue(mixed $value)

Sets the default value.

from NodeDefinition
NodeDefinition isRequired()

Sets the node as required.

from NodeDefinition
NodeDefinition treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

from NodeDefinition
NodeDefinition treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

from NodeDefinition
NodeDefinition treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

from NodeDefinition
NodeDefinition defaultNull()

Sets null as the default value.

from NodeDefinition
NodeDefinition defaultTrue()

Sets true as the default value.

from NodeDefinition
NodeDefinition defaultFalse()

Sets false as the default value.

from NodeDefinition
ExprBuilder beforeNormalization()

Sets an expression to run before the normalization.

from NodeDefinition
NodeDefinition cannotBeEmpty()

Denies the node value being empty.

from NodeDefinition
ExprBuilder validate()

Sets an expression to run for the validation.

from NodeDefinition
NodeDefinition cannotBeOverwritten(Boolean $deny = true)

Sets whether the node can be overwritten.

from NodeDefinition
setBuilder(NodeBuilder $builder)

Sets a custom children builder.

NodeBuilder children()

Returns a builder to add children nodes.

NodeDefinition prototype(string $type)

Sets a prototype for child nodes.

ArrayNodeDefinition addDefaultsIfNotSet()

Adds the default value if the node is not set in the configuration.

ArrayNodeDefinition addDefaultChildrenIfNoneSet(integer|string|array|null $children = null)

Adds children with a default value when none are defined.

ArrayNodeDefinition requiresAtLeastOneElement()

Requires the node to have at least one element.

ArrayNodeDefinition disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

ArrayNodeDefinition fixXmlConfig(string $singular, string $plural = null)

Sets a normalization rule for XML configurations.

ArrayNodeDefinition useAttributeAsKey(string $name, Boolean $removeKeyItem = true)

Sets the attribute which value is to be used as key.

ArrayNodeDefinition canBeUnset(Boolean $allow = true)

Sets whether the node can be unset.

ArrayNodeDefinition performNoDeepMerging()

Disables the deep merging of the node.

ArrayNodeDefinition ignoreExtraKeys()

Allows extra config keys to be specified under an array without throwing an exception.

ArrayNodeDefinition append(NodeDefinition $node)

Appends a node definition.

Details

at line 41
public __construct(string $name, NodeParentInterface $parent = null)

Constructor

Parameters

string $name The name of the node
NodeParentInterface $parent The parent

in NodeDefinition at line 60
public NodeDefinition setParent(NodeParentInterface $parent)

Sets the parent node.

Parameters

NodeParentInterface $parent The parent

Return Value

NodeDefinition

in NodeDefinition at line 74
public NodeDefinition info(string $info)

Sets info message.

Parameters

string $info The info text

Return Value

NodeDefinition

in NodeDefinition at line 86
public NodeDefinition example(string|array $example)

Sets example configuration.

Parameters

string|array $example

Return Value

NodeDefinition

in NodeDefinition at line 99
public NodeDefinition attribute(string $key, mixed $value)

Sets an attribute on the node.

Parameters

string $key
mixed $value

Return Value

NodeDefinition

in NodeDefinition at line 111
public NodeParentInterface end()

Returns the parent node.

Return Value

NodeParentInterface The builder of the parent node

in NodeDefinition at line 123
public NodeInterface getNode(Boolean $forceRootNode = false)

Creates the node.

Parameters

Boolean $forceRootNode Whether to force this node as the root node

Return Value

NodeInterface

in NodeDefinition at line 150
public NodeDefinition defaultValue(mixed $value)

Sets the default value.

Parameters

mixed $value The default value

Return Value

NodeDefinition

in NodeDefinition at line 163
public NodeDefinition isRequired()

Sets the node as required.

Return Value

NodeDefinition

in NodeDefinition at line 177
public NodeDefinition treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

Parameters

mixed $value

Return Value

NodeDefinition

in NodeDefinition at line 191
public NodeDefinition treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

Parameters

mixed $value

Return Value

NodeDefinition

in NodeDefinition at line 205
public NodeDefinition treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

Parameters

mixed $value

Return Value

NodeDefinition

in NodeDefinition at line 217
public NodeDefinition defaultNull()

Sets null as the default value.

Return Value

NodeDefinition

in NodeDefinition at line 227
public NodeDefinition defaultTrue()

Sets true as the default value.

Return Value

NodeDefinition

in NodeDefinition at line 237
public NodeDefinition defaultFalse()

Sets false as the default value.

Return Value

NodeDefinition

in NodeDefinition at line 247
public ExprBuilder beforeNormalization()

Sets an expression to run before the normalization.

Return Value

ExprBuilder

in NodeDefinition at line 257
public NodeDefinition cannotBeEmpty()

Denies the node value being empty.

Return Value

NodeDefinition

in NodeDefinition at line 273
public ExprBuilder validate()

Sets an expression to run for the validation.

The expression receives the value of the node and must return it. It can modify it. An exception should be thrown when the node is not valid.

Return Value

ExprBuilder

in NodeDefinition at line 285
public NodeDefinition cannotBeOverwritten(Boolean $deny = true)

Sets whether the node can be overwritten.

Parameters

Boolean $deny Whether the overwriting is forbidden or not

Return Value

NodeDefinition

at line 61
public setBuilder(NodeBuilder $builder)

Sets a custom children builder.

Parameters

NodeBuilder $builder A custom NodeBuilder

at line 71
public NodeBuilder children()

Returns a builder to add children nodes.

Return Value

NodeBuilder

at line 83
public NodeDefinition prototype(string $type)

Sets a prototype for child nodes.

Parameters

string $type the type of node

Return Value

NodeDefinition

at line 97
public ArrayNodeDefinition addDefaultsIfNotSet()

Adds the default value if the node is not set in the configuration.

This method is applicable to concrete nodes only (not to prototype nodes). If this function has been called and the node is not set during the finalization phase, it's default value will be derived from its children default values.

Return Value

ArrayNodeDefinition

at line 113
public ArrayNodeDefinition addDefaultChildrenIfNoneSet(integer|string|array|null $children = null)

Adds children with a default value when none are defined.

Parameters

integer|string|array|null $children The number of children|The child name|The children names to be added This method is applicable to prototype nodes only.

Return Value

ArrayNodeDefinition

at line 127
public ArrayNodeDefinition requiresAtLeastOneElement()

Requires the node to have at least one element.

This method is applicable to prototype nodes only.

Return Value

ArrayNodeDefinition

at line 141
public ArrayNodeDefinition disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

If used all keys have to be defined in the same configuration file.

Return Value

ArrayNodeDefinition

at line 156
public ArrayNodeDefinition fixXmlConfig(string $singular, string $plural = null)

Sets a normalization rule for XML configurations.

Parameters

string $singular The key to remap
string $plural The plural of the key for irregular plurals

Return Value

ArrayNodeDefinition

at line 191
public ArrayNodeDefinition useAttributeAsKey(string $name, Boolean $removeKeyItem = true)

Sets the attribute which value is to be used as key.

This is useful when you have an indexed array that should be an associative array. You can select an item from within the array to be the key of the particular item. For example, if "id" is the "key", then:

array(
    array('id' => 'my_name', 'foo' => 'bar'),
);

becomes

array(
    'my_name' => array('foo' => 'bar'),
);

If you'd like "'id' => 'my_name'" to still be present in the resulting array, then you can set the second argument of this method to false.

This method is applicable to prototype nodes only.

Parameters

string $name The name of the key
Boolean $removeKeyItem Whether or not the key item should be removed.

Return Value

ArrayNodeDefinition

at line 206
public ArrayNodeDefinition canBeUnset(Boolean $allow = true)

Sets whether the node can be unset.

Parameters

Boolean $allow

Return Value

ArrayNodeDefinition

at line 218
public ArrayNodeDefinition performNoDeepMerging()

Disables the deep merging of the node.

Return Value

ArrayNodeDefinition

at line 235
public ArrayNodeDefinition ignoreExtraKeys()

Allows extra config keys to be specified under an array without throwing an exception.

Those config values are simply ignored. This should be used only in special cases where you want to send an entire configuration array through a special tree that processes only part of the array.

Return Value

ArrayNodeDefinition

at line 257
public ArrayNodeDefinition append(NodeDefinition $node)

Appends a node definition.

$node = new ArrayNodeDefinition() ->children() ->scalarNode('foo')->end() ->scalarNode('baz')->end() ->end() ->append($this->getBarNodeDefinition()) ;

Parameters

NodeDefinition $node A NodeDefinition instance

Return Value

ArrayNodeDefinition This node