Documentation

ArrayNodeDefinition extends NodeDefinition
in package
implements ParentNodeDefinitionInterface

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

Tags
template
extends
author

Johannes M. Schmitt schmittjoh@gmail.com

Table of Contents

Interfaces

ParentNodeDefinitionInterface
An interface that must be implemented by nodes which can have children.

Properties

$addDefaultChildren  : int|string|array<string|int, mixed>|false|null
$addDefaults  : bool
$allowedTypes  : array<int, ExprBuilder::TYPE_*>|null
$allowEmptyValue  : bool
$allowNewKeys  : bool
$atLeastOne  : bool
$attributes  : array<string|int, mixed>
$children  : array<string|int, NodeDefinition<string|int, $this>>
$default  : bool
$defaultValue  : mixed
$deprecation  : array<string|int, mixed>
$falseEquivalent  : mixed
$ignoreExtraKeys  : bool
$key  : string|null
$merge  : MergeBuilder<string|int, $this>
$name  : string|null
$nodeBuilder  : NodeBuilder<string|int, static>
$normalization  : NormalizationBuilder<string|int, $this>
$normalizeKeys  : bool
$nullEquivalent  : mixed
$parent  : TParent|NodeInterface
$pathSeparator  : string
$performDeepMerging  : bool
$prototype  : NodeDefinition<string|int, $this>
$removeExtraKeys  : bool
$removeKeyItem  : bool
$required  : bool
$trueEquivalent  : mixed
$validation  : ValidationBuilder<string|int, $this>

Methods

__construct()  : mixed
acceptAndWrap()  : $this
Allows alternative types and wraps them into arrays.
addDefaultChildrenIfNoneSet()  : $this
Adds children with a default value when none are defined.
addDefaultsIfNotSet()  : $this
Adds the default value if the node is not set in the configuration.
append()  : $this
Appends a node definition.
arrayPrototype()  : self<$this>
attribute()  : $this
Sets an attribute on the node.
beforeNormalization()  : ExprBuilder<string|int, $this>
Sets an expression to run before the normalization.
booleanPrototype()  : BooleanNodeDefinition<string|int, $this>
canBeDisabled()  : $this
Adds an "enabled" boolean to enable the current section.
canBeEnabled()  : $this
Adds an "enabled" boolean to enable the current section.
canBeUnset()  : $this
Sets whether the node can be unset.
cannotBeEmpty()  : $this
Denies the node value being empty.
cannotBeOverwritten()  : $this
Sets whether the node can be overwritten.
children()  : NodeBuilder<string|int, static>
Returns a builder to add children nodes.
defaultFalse()  : $this
Sets false as the default value.
defaultNull()  : $this
Sets null as the default value.
defaultTrue()  : $this
Sets true as the default value.
defaultValue()  : $this
Sets the default value.
disallowNewKeysInSubsequentConfigs()  : $this
Disallows adding news keys in a subsequent configuration.
docUrl()  : $this
Sets the documentation URI, as usually put in the "@see" tag of a doc block. This can either be a URL or a file path. You can use the placeholders {package}, {version:major} and {version:minor} in the URI.
end()  : TParent
Returns the parent node.
enumPrototype()  : EnumNodeDefinition<string|int, $this>
example()  : $this
Sets example configuration.
find()  : NodeDefinition
Finds a node defined by the given $nodePath.
fixXmlConfig()  : $this
Sets a normalization rule for XML configurations.
floatPrototype()  : FloatNodeDefinition<string|int, $this>
getChildNodeDefinitions()  : array<string|int, NodeDefinition<string|int, $this>>
Gets the child node definitions.
getNode()  : NodeInterface
Creates the node.
ignoreExtraKeys()  : $this
Allows extra config keys to be specified under an array without throwing an exception.
info()  : $this
Sets info message.
integerPrototype()  : IntegerNodeDefinition<string|int, $this>
isRequired()  : $this
Sets the node as required.
normalizeKeys()  : $this
Sets whether to enable key normalization.
performNoDeepMerging()  : $this
Disables the deep merging of the node.
prototype()  : : (\Symfony\Component\Config\Definition\Builder\T is "variable" ? \Symfony\Component\Config\Definition\Builder\VariableNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "scalar" ? \Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "string" ? \Symfony\Component\Config\Definition\Builder\StringNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "boolean" ? \Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "integer" ? \Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "float" ? \Symfony\Component\Config\Definition\Builder\FloatNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "enum" ? \Symfony\Component\Config\Definition\Builder\EnumNodeDefinition<$this> : \Symfony\Component\Config\Definition\Builder\NodeDefinition<$this>))))))))">NodeDefinition<$this>))))))))
Sets a prototype for child nodes.
requiresAtLeastOneElement()  : $this
Requires the node to have at least one element.
scalarPrototype()  : ScalarNodeDefinition<string|int, $this>
setBuilder()  : void
Sets a custom children builder.
setDeprecated()  : $this
Sets the node as deprecated.
setParent()  : $this
Sets the parent node.
setPathSeparator()  : $this
Set PathSeparator to use.
stringPrototype()  : StringNodeDefinition<string|int, $this>
treatFalseLike()  : $this
Sets the equivalent value used when the node contains false.
treatNullLike()  : $this
Sets the equivalent value used when the node contains null.
treatTrueLike()  : $this
Sets the equivalent value used when the node contains true.
useAttributeAsKey()  : $this
Sets the attribute which value is to be used as key.
validate()  : ExprBuilder<string|int, $this>
Sets an expression to run for the validation.
variablePrototype()  : VariableNodeDefinition<string|int, $this>
createNode()  : NodeInterface
Instantiate and configure the node according to this definition.
getNodeBuilder()  : NodeBuilder<string|int, static>
Returns a node builder to be used to add children and prototype.
merge()  : MergeBuilder<string|int, $this>
Gets the builder for merging rules.
normalization()  : NormalizationBuilder<string|int, $this>
Gets the builder for normalization rules.
validateConcreteNode()  : void
Validate the configuration of a concrete node.
validatePrototypeNode()  : void
Validate the configuration of a prototype node.
validation()  : ValidationBuilder<string|int, $this>
Gets the builder for validation rules.

Properties

$addDefaultChildren

protected int|string|array<string|int, mixed>|false|null $addDefaultChildren = false

$deprecation

protected array<string|int, mixed> $deprecation = []

$pathSeparator

protected string $pathSeparator = \Symfony\Component\Config\Definition\BaseNode::DEFAULT_PATH_SEPARATOR

Methods

__construct()

public __construct(string|null $name[, TParent $parent = null ]) : mixed
Parameters
$name : string|null
$parent : TParent = null

acceptAndWrap()

Allows alternative types and wraps them into arrays.

public acceptAndWrap(array<int, ExprBuilder::TYPE_INT|ExprBuilder::TYPE_STRING|ExprBuilder::TYPE_BOOL|ExprBuilder::TYPE_NULL|ExprBuilder::TYPE_BACKED_ENUM> $allowedTypes[, string|null $key = null ]) : $this
Parameters
$allowedTypes : array<int, ExprBuilder::TYPE_INT|ExprBuilder::TYPE_STRING|ExprBuilder::TYPE_BOOL|ExprBuilder::TYPE_NULL|ExprBuilder::TYPE_BACKED_ENUM>
$key : string|null = null

The key to wrap the value in

Return values
$this

addDefaultChildrenIfNoneSet()

Adds children with a default value when none are defined.

public addDefaultChildrenIfNoneSet([int|string|array<string|int, mixed>|null $children = null ]) : $this

This method is applicable to prototype nodes only.

Parameters
$children : int|string|array<string|int, mixed>|null = null

The number of children|The child name|The children names to be added

Return values
$this

addDefaultsIfNotSet()

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

public addDefaultsIfNotSet() : $this

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 values
$this

append()

Appends a node definition.

public append(NodeDefinition $node) : $this

Usage:

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

Parameters
$node : NodeDefinition
Return values
$this

attribute()

Sets an attribute on the node.

public attribute(string $key, mixed $value) : $this
Parameters
$key : string
$value : mixed
Return values
$this

beforeNormalization()

Sets an expression to run before the normalization.

public beforeNormalization() : ExprBuilder<string|int, $this>
Return values
ExprBuilder<string|int, $this>

canBeDisabled()

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

public canBeDisabled() : $this

By default, the section is enabled.

Return values
$this

canBeEnabled()

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

public canBeEnabled() : $this

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 values
$this

canBeUnset()

Sets whether the node can be unset.

public canBeUnset([bool $allow = true ]) : $this
Parameters
$allow : bool = true
Return values
$this

cannotBeEmpty()

Denies the node value being empty.

public cannotBeEmpty() : $this
Return values
$this

cannotBeOverwritten()

Sets whether the node can be overwritten.

public cannotBeOverwritten([bool $deny = true ]) : $this
Parameters
$deny : bool = true
Return values
$this

defaultFalse()

Sets false as the default value.

public defaultFalse() : $this
Return values
$this

defaultNull()

Sets null as the default value.

public defaultNull() : $this
Return values
$this

defaultTrue()

Sets true as the default value.

public defaultTrue() : $this
Return values
$this

defaultValue()

Sets the default value.

public defaultValue(mixed $value) : $this
Parameters
$value : mixed
Return values
$this

disallowNewKeysInSubsequentConfigs()

Disallows adding news keys in a subsequent configuration.

public disallowNewKeysInSubsequentConfigs() : $this

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

Return values
$this

docUrl()

Sets the documentation URI, as usually put in the "@see" tag of a doc block. This can either be a URL or a file path. You can use the placeholders {package}, {version:major} and {version:minor} in the URI.

public docUrl(string $uri[, string|null $package = null ]) : $this
Parameters
$uri : string
$package : string|null = null
Return values
$this

end()

Returns the parent node.

public end() : TParent
Return values
TParent

example()

Sets example configuration.

public example(string|array<string|int, mixed> $example) : $this
Parameters
$example : string|array<string|int, mixed>
Return values
$this

fixXmlConfig()

Sets a normalization rule for XML configurations.

public fixXmlConfig(string $singular[, string|null $plural = null ]) : $this
Parameters
$singular : string

The key to remap

$plural : string|null = null

The plural of the key for irregular plurals

Return values
$this

ignoreExtraKeys()

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

public ignoreExtraKeys([bool $remove = true ]) : $this

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
$remove : bool = true

Whether to remove the extra keys

Return values
$this

info()

Sets info message.

public info(string $info) : $this
Parameters
$info : string
Return values
$this

isRequired()

Sets the node as required.

public isRequired() : $this
Return values
$this

normalizeKeys()

Sets whether to enable key normalization.

public normalizeKeys(bool $bool) : $this
Parameters
$bool : bool
Return values
$this

performNoDeepMerging()

Disables the deep merging of the node.

public performNoDeepMerging() : $this
Return values
$this

prototype()

Sets a prototype for child nodes.

public prototype(T $type) : : (\Symfony\Component\Config\Definition\Builder\T is "variable" ? \Symfony\Component\Config\Definition\Builder\VariableNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "scalar" ? \Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "string" ? \Symfony\Component\Config\Definition\Builder\StringNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "boolean" ? \Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "integer" ? \Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "float" ? \Symfony\Component\Config\Definition\Builder\FloatNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "enum" ? \Symfony\Component\Config\Definition\Builder\EnumNodeDefinition<$this> : \Symfony\Component\Config\Definition\Builder\NodeDefinition<$this>))))))))">NodeDefinition<$this>))))))))
Parameters
$type : T
Tags
template
Return values
: (\Symfony\Component\Config\Definition\Builder\T is "variable" ? \Symfony\Component\Config\Definition\Builder\VariableNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "scalar" ? \Symfony\Component\Config\Definition\Builder\ScalarNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "string" ? \Symfony\Component\Config\Definition\Builder\StringNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "boolean" ? \Symfony\Component\Config\Definition\Builder\BooleanNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "integer" ? \Symfony\Component\Config\Definition\Builder\IntegerNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "float" ? \Symfony\Component\Config\Definition\Builder\FloatNodeDefinition<$this> : (\Symfony\Component\Config\Definition\Builder\T is "enum" ? \Symfony\Component\Config\Definition\Builder\EnumNodeDefinition<$this> : \Symfony\Component\Config\Definition\Builder\NodeDefinition<$this>))))))))">NodeDefinition<$this>))))))))

requiresAtLeastOneElement()

Requires the node to have at least one element.

public requiresAtLeastOneElement() : $this

This method is applicable to prototype nodes only.

Return values
$this

setDeprecated()

Sets the node as deprecated.

public setDeprecated(string $package, string $version[, string $message = 'The child node "%node%" at path "%path%" is deprecated.' ]) : $this
Parameters
$package : string

The name of the composer package that is triggering the deprecation

$version : string

The version of the package that introduced the deprecation

$message : string = 'The child node "%node%" at path "%path%" is deprecated.'

the deprecation message to use

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

Return values
$this

setPathSeparator()

Set PathSeparator to use.

public setPathSeparator(string $separator) : $this
Parameters
$separator : string
Return values
$this

treatFalseLike()

Sets the equivalent value used when the node contains false.

public treatFalseLike(mixed $value) : $this
Parameters
$value : mixed
Return values
$this

treatNullLike()

Sets the equivalent value used when the node contains null.

public treatNullLike(mixed $value) : $this
Parameters
$value : mixed
Return values
$this

treatTrueLike()

Sets the equivalent value used when the node contains true.

public treatTrueLike(mixed $value) : $this
Parameters
$value : mixed
Return values
$this

useAttributeAsKey()

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

public useAttributeAsKey(string $name[, bool $removeKeyItem = true ]) : $this

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
$name : string

The name of the key

$removeKeyItem : bool = true

Whether or not the key item should be removed

Return values
$this

validate()

Sets an expression to run for the validation.

public validate() : ExprBuilder<string|int, $this>

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 values
ExprBuilder<string|int, $this>
On this page

Search results