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.

setParent(NodeParentInterface $parent)

Sets the parent node.

info(string $info)

Sets info message.

example(string|array $example)

Sets example configuration.

attribute(string $key, mixed $value)

Sets an attribute on the node.

end()

Returns the parent node.

getNode(bool $forceRootNode = false)

Creates the node.

defaultValue(mixed $value)

Sets the default value.

isRequired()

Sets the node as required.

treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

defaultNull()

Sets null as the default value.

defaultTrue()

Sets true as the default value.

defaultFalse()

Sets false as the default value.

beforeNormalization()

Sets an expression to run before the normalization.

cannotBeEmpty()

Denies the node value being empty.

validate()

Sets an expression to run for the validation.

cannotBeOverwritten(bool $deny = true)

Sets whether the node can be overwritten.

setBuilder(NodeBuilder $builder)

Sets a custom children builder.

children()

Returns a builder to add children nodes.

prototype(string $type)

Sets a prototype for child nodes.

addDefaultsIfNotSet()

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

addDefaultChildrenIfNoneSet(int|string|array|null $children = null)

Adds children with a default value when none are defined.

requiresAtLeastOneElement()

Requires the node to have at least one element.

disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

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

Sets a normalization rule for XML configurations.

useAttributeAsKey(string $name, bool $removeKeyItem = true)

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

canBeUnset(bool $allow = true)

Sets whether the node can be unset.

canBeEnabled()

Adds an "enabled" boolean to enable the current section.

canBeDisabled()

Adds an "enabled" boolean to enable the current section.

performNoDeepMerging()

Disables the deep merging of the node.

ignoreExtraKeys(bool $remove = true)

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

normalizeKeys(bool $bool)

Sets key normalization.

append(NodeDefinition $node)

Appends a node definition.

Details

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

Constructor.

Parameters

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

in NodeDefinition at line line 61
NodeDefinition|$this setParent(NodeParentInterface $parent)

Sets the parent node.

Parameters

NodeParentInterface $parent The parent

Return Value

NodeDefinition|$this

in NodeDefinition at line line 75
NodeDefinition|$this info(string $info)

Sets info message.

Parameters

string $info The info text

Return Value

NodeDefinition|$this

in NodeDefinition at line line 87
NodeDefinition|$this example(string|array $example)

Sets example configuration.

Parameters

string|array $example

Return Value

NodeDefinition|$this

in NodeDefinition at line line 100
NodeDefinition|$this attribute(string $key, mixed $value)

Sets an attribute on the node.

Parameters

string $key
mixed $value

Return Value

NodeDefinition|$this

in NodeDefinition at line line 112
NodeParentInterface|null end()

Returns the parent node.

Return Value

NodeParentInterface|null The builder of the parent node

in NodeDefinition at line line 124
NodeInterface getNode(bool $forceRootNode = false)

Creates the node.

Parameters

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

Return Value

NodeInterface

in NodeDefinition at line line 151
NodeDefinition|$this defaultValue(mixed $value)

Sets the default value.

Parameters

mixed $value The default value

Return Value

NodeDefinition|$this

in NodeDefinition at line line 164
NodeDefinition|$this isRequired()

Sets the node as required.

Return Value

NodeDefinition|$this

in NodeDefinition at line line 178
NodeDefinition|$this treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

Parameters

mixed $value

Return Value

NodeDefinition|$this

in NodeDefinition at line line 192
NodeDefinition|$this treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

Parameters

mixed $value

Return Value

NodeDefinition|$this

in NodeDefinition at line line 206
NodeDefinition|$this treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

Parameters

mixed $value

Return Value

NodeDefinition|$this

in NodeDefinition at line line 218
NodeDefinition|$this defaultNull()

Sets null as the default value.

Return Value

NodeDefinition|$this

in NodeDefinition at line line 228
NodeDefinition|$this defaultTrue()

Sets true as the default value.

Return Value

NodeDefinition|$this

in NodeDefinition at line line 238
NodeDefinition|$this defaultFalse()

Sets false as the default value.

Return Value

NodeDefinition|$this

in NodeDefinition at line line 248
ExprBuilder beforeNormalization()

Sets an expression to run before the normalization.

Return Value

ExprBuilder

in NodeDefinition at line line 258
NodeDefinition|$this cannotBeEmpty()

Denies the node value being empty.

Return Value

NodeDefinition|$this

in NodeDefinition at line line 274
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 line 286
NodeDefinition|$this cannotBeOverwritten(bool $deny = true)

Sets whether the node can be overwritten.

Parameters

bool $deny Whether the overwriting is forbidden or not

Return Value

NodeDefinition|$this

at line line 55
setBuilder(NodeBuilder $builder)

Sets a custom children builder.

Parameters

NodeBuilder $builder

at line line 65
children()

Returns a builder to add children nodes.

at line line 77
NodeDefinition prototype(string $type)

Sets a prototype for child nodes.

Parameters

string $type the type of node

Return Value

NodeDefinition

at line line 91
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 line 107
ArrayNodeDefinition addDefaultChildrenIfNoneSet(int|string|array|null $children = null)

Adds children with a default value when none are defined.

Parameters

int|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 line 121
ArrayNodeDefinition requiresAtLeastOneElement()

Requires the node to have at least one element.

This method is applicable to prototype nodes only.

Return Value

ArrayNodeDefinition

at line line 135
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 line 150
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 line 185
ArrayNodeDefinition useAttributeAsKey(string $name, bool $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
bool $removeKeyItem Whether or not the key item should be removed.

Return Value

ArrayNodeDefinition

at line line 200
ArrayNodeDefinition canBeUnset(bool $allow = true)

Sets whether the node can be unset.

Parameters

bool $allow

Return Value

ArrayNodeDefinition

at line line 222
ArrayNodeDefinition canBeEnabled()

Adds an "enabled" boolean to enable the current section.

By default, the section is disabled. If any configuration is specified then the node will be automatically enabled:

enableableArrayNode: {enabled: true, ...} # The config is enabled & default values get overridden enableableArrayNode: ~ # The config is enabled & use the default values enableableArrayNode: true # The config is enabled & use the default values enableableArrayNode: {other: value, ...} # The config is enabled & default values get overridden enableableArrayNode: {enabled: false, ...} # The config is disabled enableableArrayNode: false # The config is disabled

Return Value

ArrayNodeDefinition

at line line 252
ArrayNodeDefinition canBeDisabled()

Adds an "enabled" boolean to enable the current section.

By default, the section is enabled.

Return Value

ArrayNodeDefinition

at line line 272
ArrayNodeDefinition performNoDeepMerging()

Disables the deep merging of the node.

Return Value

ArrayNodeDefinition

at line line 292
ArrayNodeDefinition ignoreExtraKeys(bool $remove = true)

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

Those config values are simply ignored and removed from the resulting array. 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.

Parameters

bool $remove Whether to remove the extra keys

Return Value

ArrayNodeDefinition

at line line 307
ArrayNodeDefinition normalizeKeys(bool $bool)

Sets key normalization.

Parameters

bool $bool Whether to enable key normalization

Return Value

ArrayNodeDefinition

at line line 329
append(NodeDefinition $node)

Appends a node definition.

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

Parameters

NodeDefinition $node