Symfony2 API
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

setBuilder(NodeBuilder $builder)

NodeBuilder children()

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 canBeEnabled()

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

ArrayNodeDefinition canBeDisabled()

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

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 normalizeKeys(Boolean $bool)

Sets key normalization.

ArrayNodeDefinition append(NodeDefinition $node)

Details

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

Constructor

Parameters

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

at line 62
public setBuilder(NodeBuilder $builder)

Parameters

NodeBuilder $builder A custom NodeBuilder

at line 72
public NodeBuilder children()

Return Value

NodeBuilder

at line 84
public NodeDefinition prototype(string $type)

Sets a prototype for child nodes.

Parameters

string $type the type of node

Return Value

NodeDefinition

at line 98
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 114
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 128
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 142
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 157
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 192
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 207
public ArrayNodeDefinition canBeUnset(Boolean $allow = true)

Sets whether the node can be unset.

Parameters

Boolean $allow

Return Value

ArrayNodeDefinition

at line 229
public 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 259
public ArrayNodeDefinition canBeDisabled()

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

By default, the section is enabled.

Return Value

ArrayNodeDefinition

at line 279
public ArrayNodeDefinition performNoDeepMerging()

Disables the deep merging of the node.

Return Value

ArrayNodeDefinition

at line 296
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 310
public ArrayNodeDefinition normalizeKeys(Boolean $bool)

Sets key normalization.

Parameters

Boolean $bool Whether to enable key normalization

Return Value

ArrayNodeDefinition

at line 332
public ArrayNodeDefinition append(NodeDefinition $node)

Parameters

NodeDefinition $node A NodeDefinition instance

Return Value

ArrayNodeDefinition This node