Skip to content

Commit

Permalink
minor #26335 [Config] Handle nullable node name + fix inheritdocs (ro…
Browse files Browse the repository at this point in the history
…0NL)

This PR was squashed before being merged into the 2.7 branch (closes #26335).

Discussion
----------

[Config] Handle nullable node name + fix inheritdocs

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no-ish
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Small split from #26297 that can be merged until master/4.1. Whereas the doc fixes only apply until 3.4, hence the split.

Small change regarding `getName/Path()` for not returning a `null` value anymore which violates `NodeInterface::getName/Path()`

Remainng issue left at

https://github.com/symfony/symfony/blob/cd5f4105a43208632c8b62fd75b4dad53dcd8a41/src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php#L381-L383

which i tend to leave untouched across all branches for now.

Commits
-------

5c3e6a9 [Config] Handle nullable node name + fix inheritdocs
  • Loading branch information
nicolas-grekas committed Mar 19, 2018
2 parents 7753282 + 5c3e6a9 commit 7323372
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 68 deletions.
14 changes: 3 additions & 11 deletions src/Symfony/Component/Config/Definition/ArrayNode.php
Expand Up @@ -150,31 +150,23 @@ public function setIgnoreExtraKeys($boolean)
}

/**
* Sets the node Name.
*
* @param string $name The node's name
* {@inheritdoc}
*/
public function setName($name)
{
$this->name = $name;
}

/**
* Checks if the node has a default value.
*
* @return bool
* {@inheritdoc}
*/
public function hasDefaultValue()
{
return $this->addIfNotSet;
}

/**
* Retrieves the default value.
*
* @return array The default value
*
* @throws \RuntimeException if the node has no default value
* {@inheritdoc}
*/
public function getDefaultValue()
{
Expand Down
38 changes: 7 additions & 31 deletions src/Symfony/Component/Config/Definition/BaseNode.php
Expand Up @@ -40,7 +40,7 @@ abstract class BaseNode implements NodeInterface
*/
public function __construct($name, NodeInterface $parent = null)
{
if (false !== strpos($name, '.')) {
if (false !== strpos($name = (string) $name, '.')) {
throw new \InvalidArgumentException('The name must not contain ".".');
}

Expand Down Expand Up @@ -170,29 +170,23 @@ public function setFinalValidationClosures(array $closures)
}

/**
* Checks if this node is required.
*
* @return bool
* {@inheritdoc}
*/
public function isRequired()
{
return $this->required;
}

/**
* Returns the name of this node.
*
* @return string The Node's name
* {@inheritdoc}
*/
public function getName()
{
return $this->name;
}

/**
* Retrieves the path of this node.
*
* @return string The Node's path
* {@inheritdoc}
*/
public function getPath()
{
Expand All @@ -206,14 +200,7 @@ public function getPath()
}

/**
* Merges two values together.
*
* @param mixed $leftSide
* @param mixed $rightSide
*
* @return mixed The merged value
*
* @throws ForbiddenOverwriteException
* {@inheritdoc}
*/
final public function merge($leftSide, $rightSide)
{
Expand All @@ -233,11 +220,7 @@ final public function merge($leftSide, $rightSide)
}

/**
* Normalizes a value, applying all normalization closures.
*
* @param mixed $value Value to normalize
*
* @return mixed The normalized value
* {@inheritdoc}
*/
final public function normalize($value)
{
Expand Down Expand Up @@ -285,14 +268,7 @@ public function getParent()
}

/**
* Finalizes a value, applying all finalization closures.
*
* @param mixed $value The value to finalize
*
* @return mixed The finalized value
*
* @throws Exception
* @throws InvalidConfigurationException
* {@inheritdoc}
*/
final public function finalize($value)
{
Expand Down
Expand Up @@ -47,17 +47,15 @@ public function __construct($name, NodeParentInterface $parent = null)
}

/**
* Sets a custom children builder.
* {@inheritdoc}
*/
public function setBuilder(NodeBuilder $builder)
{
$this->nodeBuilder = $builder;
}

/**
* Returns a builder to add children nodes.
*
* @return NodeBuilder
* {@inheritdoc}
*/
public function children()
{
Expand Down Expand Up @@ -306,17 +304,7 @@ public function normalizeKeys($bool)
}

/**
* Appends a node definition.
*
* $node = new ArrayNodeDefinition()
* ->children()
* ->scalarNode('foo')->end()
* ->scalarNode('baz')->end()
* ->end()
* ->append($this->getBarNodeDefinition())
* ;
*
* @return $this
* {@inheritdoc}
*/
public function append(NodeDefinition $node)
{
Expand Down
Expand Up @@ -18,9 +18,32 @@
*/
interface ParentNodeDefinitionInterface
{
/**
* Returns a builder to add children nodes.
*
* @return NodeBuilder
*/
public function children();

/**
* Appends a node definition.
*
* Usage:
*
* $node = $parentNode
* ->children()
* ->scalarNode('foo')->end()
* ->scalarNode('baz')->end()
* ->append($this->getBarNodeDefinition())
* ->end()
* ;
*
* @return $this
*/
public function append(NodeDefinition $node);

/**
* Sets a custom children builder.
*/
public function setBuilder(NodeBuilder $builder);
}
16 changes: 14 additions & 2 deletions src/Symfony/Component/Config/Definition/NodeInterface.php
Expand Up @@ -11,6 +11,10 @@

namespace Symfony\Component\Config\Definition;

use Symfony\Component\Config\Definition\Exception\ForbiddenOverwriteException;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\Definition\Exception\InvalidTypeException;

/**
* Common Interface among all nodes.
*
Expand Down Expand Up @@ -59,11 +63,13 @@ public function hasDefaultValue();
public function getDefaultValue();

/**
* Normalizes the supplied value.
* Normalizes a value.
*
* @param mixed $value The value to normalize
*
* @return mixed The normalized value
*
* @throws InvalidTypeException if the value type is invalid
*/
public function normalize($value);

Expand All @@ -73,7 +79,10 @@ public function normalize($value);
* @param mixed $leftSide
* @param mixed $rightSide
*
* @return mixed The merged values
* @return mixed The merged value
*
* @throws ForbiddenOverwriteException if the configuration path cannot be overwritten
* @throws InvalidTypeException if the value type is invalid
*/
public function merge($leftSide, $rightSide);

Expand All @@ -83,6 +92,9 @@ public function merge($leftSide, $rightSide);
* @param mixed $value The value to finalize
*
* @return mixed The finalized value
*
* @throws InvalidTypeException if the value type is invalid
* @throws InvalidConfigurationException if the value is invalid configuration
*/
public function finalize($value);
}
Expand Up @@ -102,9 +102,7 @@ public function setDefaultValue($value)
}

/**
* Checks if the node has a default value.
*
* @return bool
* {@inheritdoc}
*/
public function hasDefaultValue()
{
Expand All @@ -126,12 +124,10 @@ public function setAddChildrenIfNoneSet($children = array('defaults'))
}

/**
* Retrieves the default value.
* {@inheritdoc}
*
* The default value could be either explicited or derived from the prototype
* default value.
*
* @return array The default value
*/
public function getDefaultValue()
{
Expand Down
3 changes: 0 additions & 3 deletions src/Symfony/Component/Config/Definition/VariableNode.php
Expand Up @@ -27,9 +27,6 @@ class VariableNode extends BaseNode implements PrototypeNodeInterface
protected $defaultValue;
protected $allowEmptyValue = true;

/**
* {@inheritdoc}
*/
public function setDefaultValue($value)
{
$this->defaultValueSet = true;
Expand Down

0 comments on commit 7323372

Please sign in to comment.