class ArrayNodeDefinition extends NodeDefinition implements ParentNodeDefinitionInterface

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

Properties

protected $name from NodeDefinition
protected $normalization from NodeDefinition
protected $validation from NodeDefinition
protected $defaultValue from NodeDefinition
protected $default from NodeDefinition
protected $required from NodeDefinition
protected $deprecationMessage from NodeDefinition
protected $merge from NodeDefinition
protected $allowEmptyValue from NodeDefinition
protected $nullEquivalent from NodeDefinition
protected $trueEquivalent from NodeDefinition
protected $falseEquivalent from NodeDefinition
protected $parent from NodeDefinition
protected $attributes from NodeDefinition
protected $performDeepMerging
protected $ignoreExtraKeys
protected $removeExtraKeys
protected $children
protected $prototype
protected $atLeastOne
protected $allowNewKeys
protected $key
protected $removeKeyItem
protected $addDefaults
protected $addDefaultChildren
protected $nodeBuilder
protected $normalizeKeys

Methods

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

No description

$this
setParent(NodeParentInterface $parent)

Sets the parent node.

$this
info(string $info)

Sets info message.

$this
example(string|array $example)

Sets example configuration.

$this
attribute(string $key, mixed $value)

Sets an attribute on the node.

getNode(bool $forceRootNode = false)

Creates the node.

$this
defaultValue(mixed $value)

Sets the default value.

$this
isRequired()

Sets the node as required.

$this
setDeprecated(string $message = 'The child node "%node%" at path "%path%" is deprecated.')

Sets the node as deprecated.

$this
treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

$this
treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

$this
treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

$this
defaultNull()

Sets null as the default value.

$this
defaultTrue()

Sets true as the default value.

$this
defaultFalse()

Sets false as the default value.

beforeNormalization()

Sets an expression to run before the normalization.

$this
cannotBeEmpty()

Denies the node value being empty.

validate()

Sets an expression to run for the validation.

$this
cannotBeOverwritten(bool $deny = true)

Sets whether the node can be overwritten.

validation()

Gets the builder for validation rules.

merge()

Gets the builder for merging rules.

normalization()

Gets the builder for normalization rules.

createNode()

Instantiate and configure the node according to this definition.

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.

$this
addDefaultsIfNotSet()

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

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

Adds children with a default value when none are defined.

$this
requiresAtLeastOneElement()

Requires the node to have at least one element.

$this
disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

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

Sets a normalization rule for XML configurations.

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

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

$this
canBeUnset(bool $allow = true)

Sets whether the node can be unset.

$this
canBeEnabled()

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

$this
canBeDisabled()

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

$this
performNoDeepMerging()

Disables the deep merging of the node.

$this
ignoreExtraKeys(bool $remove = true)

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

$this
normalizeKeys(bool $bool)

Sets key normalization.

$this
append(NodeDefinition $node)

Appends a node definition.

getNodeBuilder()

Returns a node builder to be used to add children and prototype.

validateConcreteNode(ArrayNode $node)

Validate the configuration of a concrete node.

validatePrototypeNode(PrototypedArrayNode $node)

Validate the configuration of a prototype node.

Details

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

Parameters

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

in NodeDefinition at line 54
$this setParent(NodeParentInterface $parent)

Sets the parent node.

Parameters

NodeParentInterface $parent

Return Value

$this

in NodeDefinition at line 68
$this info(string $info)

Sets info message.

Parameters

string $info The info text

Return Value

$this

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

Sets example configuration.

Parameters

string|array $example

Return Value

$this

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

Sets an attribute on the node.

Parameters

string $key
mixed $value

Return Value

$this

in NodeDefinition at line 117
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 144
$this defaultValue(mixed $value)

Sets the default value.

Parameters

mixed $value The default value

Return Value

$this

in NodeDefinition at line 157
$this isRequired()

Sets the node as required.

Return Value

$this

in NodeDefinition at line 174
$this setDeprecated(string $message = 'The child node "%node%" at path "%path%" is deprecated.')

Sets the node as deprecated.

You can use %node% and %path% placeholders in your message to display, respectively, the node name and its complete path.

Parameters

string $message Deprecation message

Return Value

$this

in NodeDefinition at line 188
$this treatNullLike(mixed $value)

Sets the equivalent value used when the node contains null.

Parameters

mixed $value

Return Value

$this

in NodeDefinition at line 202
$this treatTrueLike(mixed $value)

Sets the equivalent value used when the node contains true.

Parameters

mixed $value

Return Value

$this

in NodeDefinition at line 216
$this treatFalseLike(mixed $value)

Sets the equivalent value used when the node contains false.

Parameters

mixed $value

Return Value

$this

in NodeDefinition at line 228
$this defaultNull()

Sets null as the default value.

Return Value

$this

in NodeDefinition at line 238
$this defaultTrue()

Sets true as the default value.

Return Value

$this

in NodeDefinition at line 248
$this defaultFalse()

Sets false as the default value.

Return Value

$this

in NodeDefinition at line 258
ExprBuilder beforeNormalization()

Sets an expression to run before the normalization.

Return Value

ExprBuilder

in NodeDefinition at line 268
$this cannotBeEmpty()

Denies the node value being empty.

Return Value

$this

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

Sets whether the node can be overwritten.

Parameters

bool $deny Whether the overwriting is forbidden or not

Return Value

$this

in NodeDefinition at line 308
protected ValidationBuilder validation()

Gets the builder for validation rules.

Return Value

ValidationBuilder

in NodeDefinition at line 322
protected MergeBuilder merge()

Gets the builder for merging rules.

Return Value

MergeBuilder

in NodeDefinition at line 336
protected NormalizationBuilder normalization()

Gets the builder for normalization rules.

Return Value

NormalizationBuilder

at line 393
protected NodeInterface createNode()

Instantiate and configure the node according to this definition.

Return Value

NodeInterface The node instance

Exceptions

InvalidDefinitionException When the definition is invalid

at line 53
setBuilder(NodeBuilder $builder)

Sets a custom children builder.

Parameters

NodeBuilder $builder

at line 61
NodeBuilder children()

Returns a builder to add children nodes.

Return Value

NodeBuilder

at line 73
NodeDefinition prototype(string $type)

Sets a prototype for child nodes.

Parameters

string $type The type of node

Return Value

NodeDefinition

at line 81
VariableNodeDefinition variablePrototype()

Return Value

VariableNodeDefinition

at line 89
ScalarNodeDefinition scalarPrototype()

Return Value

ScalarNodeDefinition

at line 97
BooleanNodeDefinition booleanPrototype()

Return Value

BooleanNodeDefinition

at line 105
IntegerNodeDefinition integerPrototype()

Return Value

IntegerNodeDefinition

at line 113
FloatNodeDefinition floatPrototype()

Return Value

FloatNodeDefinition

at line 121
ArrayNodeDefinition arrayPrototype()

Return Value

ArrayNodeDefinition

at line 129
EnumNodeDefinition enumPrototype()

Return Value

EnumNodeDefinition

at line 143
$this 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

$this

at line 159
$this addDefaultChildrenIfNoneSet(int|string|array|null $children = null)

Adds children with a default value when none are defined.

This method is applicable to prototype nodes only.

Parameters

int|string|array|null $children The number of children|The child name|The children names to be added

Return Value

$this

at line 173
$this requiresAtLeastOneElement()

Requires the node to have at least one element.

This method is applicable to prototype nodes only.

Return Value

$this

at line 187
$this disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

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

Return Value

$this

at line 202
$this 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

$this

at line 237
$this 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:

[
    ['id' => 'my_name', 'foo' => 'bar'],
];

becomes

[
    'my_name' => ['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

$this

at line 252
$this canBeUnset(bool $allow = true)

Sets whether the node can be unset.

Parameters

bool $allow

Return Value

$this

at line 274
$this 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

$this

at line 304
$this canBeDisabled()

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

By default, the section is enabled.

Return Value

$this

at line 324
$this performNoDeepMerging()

Disables the deep merging of the node.

Return Value

$this

at line 344
$this ignoreExtraKeys(bool $remove = true)

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

Those config values are 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

$this

at line 359
$this normalizeKeys(bool $bool)

Sets key normalization.

Parameters

bool $bool Whether to enable key normalization

Return Value

$this

at line 369
$this append(NodeDefinition $node)

Appends a node definition.

Usage:

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

Parameters

NodeDefinition $node

Return Value

$this

at line 381
protected NodeBuilder getNodeBuilder()

Returns a node builder to be used to add children and prototype.

Return Value

NodeBuilder The node builder

at line 470
protected validateConcreteNode(ArrayNode $node)

Validate the configuration of a concrete node.

Parameters

ArrayNode $node

Exceptions

InvalidDefinitionException

at line 500
protected validatePrototypeNode(PrototypedArrayNode $node)

Validate the configuration of a prototype node.

Parameters

PrototypedArrayNode $node

Exceptions

InvalidDefinitionException