Definition\Builder\ArrayNodeDefinition (Component\Config)
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. | ||
NodeDefinition|$this | setParent(NodeParentInterface $parent) Sets the parent node. | from NodeDefinition |
NodeDefinition|$this | info(string $info) Sets info message. | from NodeDefinition |
NodeDefinition|$this | example(string|array $example) Sets example configuration. | from NodeDefinition |
NodeDefinition|$this | attribute(string $key, mixed $value) Sets an attribute on the node. | from NodeDefinition |
NodeParentInterface|null | end() Returns the parent node. | from NodeDefinition |
NodeInterface | getNode(bool $forceRootNode = false) Creates the node. | from NodeDefinition |
NodeDefinition|$this | defaultValue(mixed $value) Sets the default value. | from NodeDefinition |
NodeDefinition|$this | isRequired() Sets the node as required. | from NodeDefinition |
NodeDefinition|$this | treatNullLike(mixed $value) Sets the equivalent value used when the node contains null. | from NodeDefinition |
NodeDefinition|$this | treatTrueLike(mixed $value) Sets the equivalent value used when the node contains true. | from NodeDefinition |
NodeDefinition|$this | treatFalseLike(mixed $value) Sets the equivalent value used when the node contains false. | from NodeDefinition |
NodeDefinition|$this | defaultNull() Sets null as the default value. | from NodeDefinition |
NodeDefinition|$this | defaultTrue() Sets true as the default value. | from NodeDefinition |
NodeDefinition|$this | defaultFalse() Sets false as the default value. | from NodeDefinition |
ExprBuilder | beforeNormalization() Sets an expression to run before the normalization. | from NodeDefinition |
NodeDefinition|$this | cannotBeEmpty() Denies the node value being empty. | from NodeDefinition |
ExprBuilder | validate() Sets an expression to run for the validation. | from NodeDefinition |
NodeDefinition|$this | cannotBeOverwritten(bool $deny = true) Sets whether the node can be overwritten. | from NodeDefinition |
setBuilder(NodeBuilder $builder) Sets a custom children builder. | ||
NodeBuilder | children() Returns a builder to add children nodes. | |
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(int|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, bool $removeKeyItem = true) Sets the attribute which value is to be used as key. | |
ArrayNodeDefinition | canBeUnset(bool $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(bool $remove = true) Allows extra config keys to be specified under an array without throwing an exception. | |
ArrayNodeDefinition | normalizeKeys(bool $bool) Sets key normalization. | |
ArrayNodeDefinition | append(NodeDefinition $node) Appends a node definition. |
Details
public __construct(string $name, NodeParentInterface $parent = null)
Constructor.
public NodeDefinition|$this setParent(NodeParentInterface $parent)
Sets the parent node.
public NodeDefinition|$this info(string $info)
Sets info message.
public NodeDefinition|$this example(string|array $example)
Sets example configuration.
public NodeDefinition|$this attribute(string $key, mixed $value)
Sets an attribute on the node.
public NodeParentInterface|null end()
Returns the parent node.
public NodeInterface getNode(bool $forceRootNode = false)
Creates the node.
public NodeDefinition|$this defaultValue(mixed $value)
Sets the default value.
public NodeDefinition|$this isRequired()
Sets the node as required.
public NodeDefinition|$this treatNullLike(mixed $value)
Sets the equivalent value used when the node contains null.
public NodeDefinition|$this treatTrueLike(mixed $value)
Sets the equivalent value used when the node contains true.
public NodeDefinition|$this treatFalseLike(mixed $value)
Sets the equivalent value used when the node contains false.
public NodeDefinition|$this defaultNull()
Sets null as the default value.
public NodeDefinition|$this defaultTrue()
Sets true as the default value.
public NodeDefinition|$this defaultFalse()
Sets false as the default value.
public ExprBuilder beforeNormalization()
Sets an expression to run before the normalization.
public NodeDefinition|$this cannotBeEmpty()
Denies the node value being empty.
public 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.
public NodeDefinition|$this cannotBeOverwritten(bool $deny = true)
Sets whether the node can be overwritten.
public setBuilder(NodeBuilder $builder)
Sets a custom children builder.
public NodeBuilder children()
Returns a builder to add children nodes.
public NodeDefinition prototype(string $type)
Sets a prototype for child nodes.
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.
public ArrayNodeDefinition addDefaultChildrenIfNoneSet(int|string|array|null $children = null)
Adds children with a default value when none are defined.
public ArrayNodeDefinition requiresAtLeastOneElement()
Requires the node to have at least one element.
This method is applicable to prototype nodes only.
public ArrayNodeDefinition disallowNewKeysInSubsequentConfigs()
Disallows adding news keys in a subsequent configuration.
If used all keys have to be defined in the same configuration file.
public ArrayNodeDefinition fixXmlConfig(string $singular, string $plural = null)
Sets a normalization rule for XML configurations.
public 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.
public ArrayNodeDefinition canBeUnset(bool $allow = true)
Sets whether the node can be unset.
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
public ArrayNodeDefinition canBeDisabled()
Adds an "enabled" boolean to enable the current section.
By default, the section is enabled.
public ArrayNodeDefinition performNoDeepMerging()
Disables the deep merging of the node.
public 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.
public ArrayNodeDefinition normalizeKeys(bool $bool)
Sets key normalization.
public ArrayNodeDefinition append(NodeDefinition $node)
Appends a node definition.
$node = new ArrayNodeDefinition() ->children() ->scalarNode('foo')->end() ->scalarNode('baz')->end() ->end() ->append($this->getBarNodeDefinition()) ;
© 2004–2016 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/3.0/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.html