PrototypedArrayNode
extends ArrayNode
in package
Represents a prototyped Array node in the config tree.
Tags
Table of Contents
Constants
- DEFAULT_PATH_SEPARATOR = '.'
Properties
- $addIfNotSet : mixed
- $allowFalse : mixed
- $allowNewKeys : mixed
- $allowOverwrite : mixed
- $attributes : mixed
- $children : mixed
- $defaultChildren : mixed
- $defaultValue : mixed
- $deprecation : mixed
- $equivalentValues : mixed
- $finalValidationClosures : mixed
- $ignoreExtraKeys : mixed
- $keyAttribute : mixed
- $minNumberOfElements : mixed
- $name : mixed
- $normalizationClosures : mixed
- $normalizedTypes : mixed
- $normalizeKeys : mixed
- $parent : mixed
- $pathSeparator : mixed
- $performDeepMerging : mixed
- $prototype : mixed
- $removeExtraKeys : mixed
- $removeKeyAttribute : mixed
- $required : mixed
- $xmlRemappings : mixed
- $valuePrototypes : array<string|int, NodeInterface>
Methods
- __construct() : mixed
- addChild() : never
- Disable adding concrete children for prototyped nodes.
- addEquivalentValue() : void
- Adds an equivalent value.
- finalize() : mixed
- Finalizes a value.
- getAttribute() : mixed
- getAttributes() : array<string|int, mixed>
- getChildren() : array<string, NodeInterface>
- Retrieves the children of this node.
- getDefaultValue() : mixed
- The default value could be either explicited or derived from the prototype default value.
- getDeprecation() : array<string|int, mixed>
- getExample() : string|array<string|int, mixed>|null
- Retrieves the example configuration for this node.
- getInfo() : string|null
- Returns info message.
- getKeyAttribute() : string|null
- Retrieves the name of the attribute which value should be used as key.
- getName() : string
- Returns the name of the node.
- getNormalizedTypes() : array<string|int, mixed>
- Gets the list of types supported by normalization.
- getParent() : NodeInterface|null
- Returns parent node for this node.
- getPath() : string
- Returns the path of the node.
- getPrototype() : PrototypeNodeInterface
- Retrieves the prototype.
- getXmlRemappings() : array<string|int, mixed>
- Gets the xml remappings that should be performed.
- hasAttribute() : bool
- hasDefaultValue() : bool
- Returns true when the node has a default value.
- isDeprecated() : bool
- Checks if this node is deprecated.
- isRequired() : bool
- Returns true when the node is required.
- merge() : mixed
- Merges two values together.
- normalize() : mixed
- Normalizes a value.
- removeAttribute() : void
- setAddChildrenIfNoneSet() : void
- Adds default children when none are set.
- setAddIfNotSet() : void
- Sets whether to add default values for this array if it has not been defined in any of the configuration files.
- setAllowFalse() : void
- Sets whether false is allowed as value indicating that the array should be unset.
- setAllowNewKeys() : void
- Sets whether new keys can be defined in subsequent configurations.
- setAllowOverwrite() : void
- Sets if this node can be overridden.
- setAttribute() : void
- setAttributes() : void
- setDefaultValue() : void
- Sets the default value of this node.
- setDeprecated() : void
- Sets this node as deprecated.
- setExample() : void
- Sets the example configuration for this node.
- setFinalValidationClosures() : void
- Sets the closures used for final validation.
- setIgnoreExtraKeys() : void
- Whether extra keys should just be ignored without an exception.
- setInfo() : void
- Sets an info message.
- setKeyAttribute() : void
- Sets the attribute which value is to be used as key.
- setMinNumberOfElements() : void
- Sets the minimum number of elements that a prototype based node must contain. By default this is zero, meaning no elements.
- setName() : void
- Sets the name of the node.
- setNormalizationClosures() : void
- Sets the closures used for normalization.
- setNormalizedTypes() : void
- Sets the list of types supported by normalization.
- setNormalizeKeys() : void
- setPerformDeepMerging() : void
- Sets if deep merging should occur.
- setPrototype() : void
- Sets the node prototype.
- setRequired() : void
- Set this node as required.
- setXmlRemappings() : void
- Sets the xml remappings that should be performed.
- shouldIgnoreExtraKeys() : bool
- Returns true when extra keys should be ignored without an exception.
- allowPlaceholders() : bool
- Tests if placeholder values are allowed for this node.
- finalizeValue() : mixed
- Finalizes a value.
- getValidPlaceholderTypes() : array<string|int, mixed>
- Gets allowed dynamic types for this node.
- isHandlingPlaceholder() : bool
- Tests if a placeholder is being handled currently.
- mergeValues() : mixed
- Merges two values together.
- normalizeValue() : mixed
- Normalizes the value.
- preNormalize() : mixed
- Namely, you mostly have foo_bar in YAML while you have foo-bar in XML.
- remapXml() : array<string|int, mixed>
- Remaps multiple singular values to a single plural value.
- validateType() : void
- Validates the type of a Node.
- getPrototypeForChild() : mixed
- Returns a prototype for the child node that is associated to $key in the value array.
Constants
DEFAULT_PATH_SEPARATOR
public
mixed
DEFAULT_PATH_SEPARATOR
= '.'
Properties
$addIfNotSet
protected
mixed
$addIfNotSet
= false
$allowFalse
protected
mixed
$allowFalse
= false
$allowNewKeys
protected
mixed
$allowNewKeys
= true
$allowOverwrite
protected
mixed
$allowOverwrite
= true
$attributes
protected
mixed
$attributes
= []
$children
protected
mixed
$children
= []
$defaultChildren
protected
mixed
$defaultChildren
$defaultValue
protected
mixed
$defaultValue
= []
$deprecation
protected
mixed
$deprecation
= []
$equivalentValues
protected
mixed
$equivalentValues
= []
$finalValidationClosures
protected
mixed
$finalValidationClosures
= []
$ignoreExtraKeys
protected
mixed
$ignoreExtraKeys
= false
$keyAttribute
protected
mixed
$keyAttribute
$minNumberOfElements
protected
mixed
$minNumberOfElements
= 0
$name
protected
mixed
$name
$normalizationClosures
protected
mixed
$normalizationClosures
= []
$normalizedTypes
protected
mixed
$normalizedTypes
= []
$normalizeKeys
protected
mixed
$normalizeKeys
= true
$parent
protected
mixed
$parent
$pathSeparator
protected
mixed
$pathSeparator
$performDeepMerging
protected
mixed
$performDeepMerging
= true
$prototype
protected
mixed
$prototype
$removeExtraKeys
protected
mixed
$removeExtraKeys
= true
$removeKeyAttribute
protected
mixed
$removeKeyAttribute
= false
$required
protected
mixed
$required
= false
$xmlRemappings
protected
mixed
$xmlRemappings
= []
$valuePrototypes
private
array<string|int, NodeInterface>
$valuePrototypes
= []
An array of the prototypes of the simplified value children
Methods
__construct()
public
__construct(string|null $name[, NodeInterface|null $parent = null ][, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR ]) : mixed
Parameters
- $name : string|null
- $parent : NodeInterface|null = null
- $pathSeparator : string = self::DEFAULT_PATH_SEPARATOR
Tags
addChild()
Disable adding concrete children for prototyped nodes.
public
addChild(NodeInterface $node) : never
Parameters
- $node : NodeInterface
Tags
Return values
neveraddEquivalentValue()
Adds an equivalent value.
public
addEquivalentValue(mixed $originalValue, mixed $equivalentValue) : void
Parameters
- $originalValue : mixed
- $equivalentValue : mixed
finalize()
Finalizes a value.
public
final finalize(mixed $value) : mixed
Parameters
- $value : mixed
getAttribute()
public
getAttribute(string $key[, mixed $default = null ]) : mixed
Parameters
- $key : string
- $default : mixed = null
getAttributes()
public
getAttributes() : array<string|int, mixed>
Return values
array<string|int, mixed>getChildren()
Retrieves the children of this node.
public
getChildren() : array<string, NodeInterface>
Return values
array<string, NodeInterface>getDefaultValue()
The default value could be either explicited or derived from the prototype default value.
public
getDefaultValue() : mixed
getDeprecation()
public
getDeprecation(string $node, string $path) : array<string|int, mixed>
Parameters
- $node : string
-
The configuration node name
- $path : string
-
The path of the node
Return values
array<string|int, mixed>getExample()
Retrieves the example configuration for this node.
public
getExample() : string|array<string|int, mixed>|null
Return values
string|array<string|int, mixed>|nullgetInfo()
Returns info message.
public
getInfo() : string|null
Return values
string|nullgetKeyAttribute()
Retrieves the name of the attribute which value should be used as key.
public
getKeyAttribute() : string|null
Return values
string|nullgetName()
Returns the name of the node.
public
getName() : string
Return values
stringgetNormalizedTypes()
Gets the list of types supported by normalization.
public
getNormalizedTypes() : array<string|int, mixed>
see ExprBuilder::TYPE_* constants.
Return values
array<string|int, mixed>getParent()
Returns parent node for this node.
public
getParent() : NodeInterface|null
Return values
NodeInterface|nullgetPath()
Returns the path of the node.
public
getPath() : string
Return values
stringgetPrototype()
Retrieves the prototype.
public
getPrototype() : PrototypeNodeInterface
Return values
PrototypeNodeInterfacegetXmlRemappings()
Gets the xml remappings that should be performed.
public
getXmlRemappings() : array<string|int, mixed>
Return values
array<string|int, mixed> —an array of the form [[string, string]]
hasAttribute()
public
hasAttribute(string $key) : bool
Parameters
- $key : string
Return values
boolhasDefaultValue()
Returns true when the node has a default value.
public
hasDefaultValue() : bool
Return values
boolisDeprecated()
Checks if this node is deprecated.
public
isDeprecated() : bool
Return values
boolisRequired()
Returns true when the node is required.
public
isRequired() : bool
Return values
boolmerge()
Merges two values together.
public
final merge(mixed $leftSide, mixed $rightSide) : mixed
Parameters
- $leftSide : mixed
- $rightSide : mixed
normalize()
Normalizes a value.
public
final normalize(mixed $value) : mixed
Parameters
- $value : mixed
removeAttribute()
public
removeAttribute(string $key) : void
Parameters
- $key : string
setAddChildrenIfNoneSet()
Adds default children when none are set.
public
setAddChildrenIfNoneSet([int|string|array<string|int, mixed>|null $children = ['defaults'] ]) : void
Parameters
- $children : int|string|array<string|int, mixed>|null = ['defaults']
-
The number of children|The child name|The children names to be added
setAddIfNotSet()
Sets whether to add default values for this array if it has not been defined in any of the configuration files.
public
setAddIfNotSet(bool $boolean) : void
Parameters
- $boolean : bool
setAllowFalse()
Sets whether false is allowed as value indicating that the array should be unset.
public
setAllowFalse(bool $allow) : void
Parameters
- $allow : bool
setAllowNewKeys()
Sets whether new keys can be defined in subsequent configurations.
public
setAllowNewKeys(bool $allow) : void
Parameters
- $allow : bool
setAllowOverwrite()
Sets if this node can be overridden.
public
setAllowOverwrite(bool $allow) : void
Parameters
- $allow : bool
setAttribute()
public
setAttribute(string $key, mixed $value) : void
Parameters
- $key : string
- $value : mixed
setAttributes()
public
setAttributes(array<string|int, mixed> $attributes) : void
Parameters
- $attributes : array<string|int, mixed>
setDefaultValue()
Sets the default value of this node.
public
setDefaultValue(array<string|int, mixed> $value) : void
Parameters
- $value : array<string|int, mixed>
setDeprecated()
Sets this node as deprecated.
public
setDeprecated(string $package, string $version[, string $message = 'The child node "%node%" at path "%path%" is deprecated.' ]) : void
You can use %node% and %path% placeholders in your message to display, respectively, the node name and its complete path.
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
setExample()
Sets the example configuration for this node.
public
setExample(string|array<string|int, mixed> $example) : void
Parameters
- $example : string|array<string|int, mixed>
setFinalValidationClosures()
Sets the closures used for final validation.
public
setFinalValidationClosures(array<string|int, Closure> $closures) : void
Parameters
- $closures : array<string|int, Closure>
-
An array of Closures used for final validation
setIgnoreExtraKeys()
Whether extra keys should just be ignored without an exception.
public
setIgnoreExtraKeys(bool $boolean[, bool $remove = true ]) : void
Parameters
- $boolean : bool
-
To allow extra keys
- $remove : bool = true
-
To remove extra keys
setInfo()
Sets an info message.
public
setInfo(string $info) : void
Parameters
- $info : string
setKeyAttribute()
Sets the attribute which value is to be used as key.
public
setKeyAttribute(string $attribute[, bool $remove = true ]) : void
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.
Parameters
- $attribute : string
-
The name of the attribute which value is to be used as a key
- $remove : bool = true
-
Whether or not to remove the key
setMinNumberOfElements()
Sets the minimum number of elements that a prototype based node must contain. By default this is zero, meaning no elements.
public
setMinNumberOfElements(int $number) : void
Parameters
- $number : int
setName()
Sets the name of the node.
public
setName(string $name) : void
Parameters
- $name : string
setNormalizationClosures()
Sets the closures used for normalization.
public
setNormalizationClosures(array<string|int, Closure> $closures) : void
Parameters
- $closures : array<string|int, Closure>
-
An array of Closures used for normalization
setNormalizedTypes()
Sets the list of types supported by normalization.
public
setNormalizedTypes(array<string|int, mixed> $types) : void
see ExprBuilder::TYPE_* constants.
Parameters
- $types : array<string|int, mixed>
setNormalizeKeys()
public
setNormalizeKeys(bool $normalizeKeys) : void
Parameters
- $normalizeKeys : bool
setPerformDeepMerging()
Sets if deep merging should occur.
public
setPerformDeepMerging(bool $boolean) : void
Parameters
- $boolean : bool
setPrototype()
Sets the node prototype.
public
setPrototype(PrototypeNodeInterface $node) : void
Parameters
- $node : PrototypeNodeInterface
setRequired()
Set this node as required.
public
setRequired(bool $boolean) : void
Parameters
- $boolean : bool
setXmlRemappings()
Sets the xml remappings that should be performed.
public
setXmlRemappings(array<string|int, mixed> $remappings) : void
Parameters
- $remappings : array<string|int, mixed>
-
An array of the form [[string, string]]
shouldIgnoreExtraKeys()
Returns true when extra keys should be ignored without an exception.
public
shouldIgnoreExtraKeys() : bool
Return values
boolallowPlaceholders()
Tests if placeholder values are allowed for this node.
protected
allowPlaceholders() : bool
Return values
boolfinalizeValue()
Finalizes a value.
protected
finalizeValue(mixed $value) : mixed
Parameters
- $value : mixed
getValidPlaceholderTypes()
Gets allowed dynamic types for this node.
protected
getValidPlaceholderTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>isHandlingPlaceholder()
Tests if a placeholder is being handled currently.
protected
isHandlingPlaceholder() : bool
Return values
boolmergeValues()
Merges two values together.
protected
mergeValues(mixed $leftSide, mixed $rightSide) : mixed
Parameters
- $leftSide : mixed
- $rightSide : mixed
normalizeValue()
Normalizes the value.
protected
normalizeValue(mixed $value) : mixed
Parameters
- $value : mixed
Tags
preNormalize()
Namely, you mostly have foo_bar in YAML while you have foo-bar in XML.
protected
preNormalize(mixed $value) : mixed
After running this method, all keys are normalized to foo_bar.
If you have a mixed key like foo-bar_moo, it will not be altered. The key will also not be altered if the target key already exists.
Parameters
- $value : mixed
remapXml()
Remaps multiple singular values to a single plural value.
protected
remapXml(array<string|int, mixed> $value) : array<string|int, mixed>
Parameters
- $value : array<string|int, mixed>
Return values
array<string|int, mixed>validateType()
Validates the type of a Node.
protected
validateType(mixed $value) : void
Parameters
- $value : mixed
getPrototypeForChild()
Returns a prototype for the child node that is associated to $key in the value array.
private
getPrototypeForChild(string $key) : mixed
For general child nodes, this will be $this->prototype. But if $this->removeKeyAttribute is true and there are only two keys in the child node: one is same as this->keyAttribute and the other is 'value', then the prototype will be different.
For example, assume $this->keyAttribute is 'name' and the value array is as follows:
[
[
'name' => 'name001',
'value' => 'value001'
]
]
Now, the key is 0 and the child node is:
[
'name' => 'name001',
'value' => 'value001'
]
When normalizing the value array, the 'name' element will removed from the child node and its value becomes the new key of the child node:
[
'name001' => ['value' => 'value001']
]
Now only 'value' element is left in the child node which can be further simplified into a string:
['name001' => 'value001']
Now, the key becomes 'name001' and the child node becomes 'value001' and the prototype of child node 'name001' should be a ScalarNode instead of an ArrayNode instance.
Parameters
- $key : string