Skip to content

Commit 15e05e1

Browse files
bburnichonnicolas-grekas
authored andcommitted
Add feature allowing change of Path Separator
1 parent 2aa54b8 commit 15e05e1

19 files changed

+254
-22
lines changed

UPGRADE-4.1.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
UPGRADE FROM 4.0 to 4.1
22
=======================
33

4+
Config
5+
------
6+
7+
* Implementing `ParentNodeDefinitionInterface` without the `getChildNodeDefinitions()` method
8+
is deprecated and will be unsupported in 5.0.
9+
410
EventDispatcher
511
---------------
612

UPGRADE-5.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 4.x to 5.0
22
=======================
33

4+
Config
5+
------
6+
7+
* Added the `getChildNodeDefinitions()` method to `ParentNodeDefinitionInterface`.
8+
49
EventDispatcher
510
---------------
611

src/Symfony/Component/Config/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
4.1.0
5+
-----
6+
7+
* added `setPathSeparator` method to `NodeBuilder` class
8+
* added third `$pathSeparator` constructor argument to `BaseNode`
9+
410
4.0.0
511
-----
612

src/Symfony/Component/Config/Definition/BaseNode.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
abstract class BaseNode implements NodeInterface
2525
{
26+
const DEFAULT_PATH_SEPARATOR = '.';
27+
2628
protected $name;
2729
protected $parent;
2830
protected $normalizationClosures = array();
@@ -32,18 +34,20 @@ abstract class BaseNode implements NodeInterface
3234
protected $deprecationMessage = null;
3335
protected $equivalentValues = array();
3436
protected $attributes = array();
37+
protected $pathSeparator;
3538

3639
/**
3740
* @throws \InvalidArgumentException if the name contains a period
3841
*/
39-
public function __construct(?string $name, NodeInterface $parent = null)
42+
public function __construct(?string $name, NodeInterface $parent = null, string $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
4043
{
41-
if (false !== strpos($name, '.')) {
42-
throw new \InvalidArgumentException('The name must not contain ".".');
44+
if (false !== strpos($name, $pathSeparator)) {
45+
throw new \InvalidArgumentException('The name must not contain "'.$pathSeparator.'".');
4346
}
4447

4548
$this->name = $name;
4649
$this->parent = $parent;
50+
$this->pathSeparator = $pathSeparator;
4751
}
4852

4953
public function setAttribute($key, $value)
@@ -230,13 +234,11 @@ public function getName()
230234
*/
231235
public function getPath()
232236
{
233-
$path = $this->name;
234-
235237
if (null !== $this->parent) {
236-
$path = $this->parent->getPath().'.'.$path;
238+
return $this->parent->getPath().$this->pathSeparator.$this->name;
237239
}
238240

239-
return $path;
241+
return $this->name;
240242
}
241243

242244
/**

src/Symfony/Component/Config/Definition/Builder/ArrayNodeDefinition.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ protected function getNodeBuilder()
407407
protected function createNode()
408408
{
409409
if (null === $this->prototype) {
410-
$node = new ArrayNode($this->name, $this->parent);
410+
$node = new ArrayNode($this->name, $this->parent, $this->pathSeparator);
411411

412412
$this->validateConcreteNode($node);
413413

@@ -418,7 +418,7 @@ protected function createNode()
418418
$node->addChild($child->getNode());
419419
}
420420
} else {
421-
$node = new PrototypedArrayNode($this->name, $this->parent);
421+
$node = new PrototypedArrayNode($this->name, $this->parent, $this->pathSeparator);
422422

423423
$this->validatePrototypeNode($node);
424424

@@ -545,4 +545,12 @@ protected function validatePrototypeNode(PrototypedArrayNode $node)
545545
}
546546
}
547547
}
548+
549+
/**
550+
* @return NodeDefinition[]
551+
*/
552+
public function getChildNodeDefinitions()
553+
{
554+
return $this->children;
555+
}
548556
}

src/Symfony/Component/Config/Definition/Builder/BooleanNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct(?string $name, NodeParentInterface $parent = null)
3838
*/
3939
protected function instantiateNode()
4040
{
41-
return new BooleanNode($this->name, $this->parent);
41+
return new BooleanNode($this->name, $this->parent, $this->pathSeparator);
4242
}
4343

4444
/**

src/Symfony/Component/Config/Definition/Builder/EnumNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ protected function instantiateNode()
5151
throw new \RuntimeException('You must call ->values() on enum nodes.');
5252
}
5353

54-
return new EnumNode($this->name, $this->parent, $this->values);
54+
return new EnumNode($this->name, $this->parent, $this->values, $this->pathSeparator);
5555
}
5656
}

src/Symfony/Component/Config/Definition/Builder/FloatNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class FloatNodeDefinition extends NumericNodeDefinition
2727
*/
2828
protected function instantiateNode()
2929
{
30-
return new FloatNode($this->name, $this->parent, $this->min, $this->max);
30+
return new FloatNode($this->name, $this->parent, $this->min, $this->max, $this->pathSeparator);
3131
}
3232
}

src/Symfony/Component/Config/Definition/Builder/IntegerNodeDefinition.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ class IntegerNodeDefinition extends NumericNodeDefinition
2727
*/
2828
protected function instantiateNode()
2929
{
30-
return new IntegerNode($this->name, $this->parent, $this->min, $this->max);
30+
return new IntegerNode($this->name, $this->parent, $this->min, $this->max, $this->pathSeparator);
3131
}
3232
}

src/Symfony/Component/Config/Definition/Builder/NodeDefinition.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Config\Definition\Builder;
1313

14+
use Symfony\Component\Config\Definition\BaseNode;
1415
use Symfony\Component\Config\Definition\NodeInterface;
1516
use Symfony\Component\Config\Definition\Exception\InvalidDefinitionException;
1617

@@ -33,6 +34,7 @@ abstract class NodeDefinition implements NodeParentInterface
3334
protected $nullEquivalent;
3435
protected $trueEquivalent = true;
3536
protected $falseEquivalent = false;
37+
protected $pathSeparator = BaseNode::DEFAULT_PATH_SEPARATOR;
3638
protected $parent;
3739
protected $attributes = array();
3840

@@ -346,4 +348,28 @@ protected function normalization()
346348
* @throws InvalidDefinitionException When the definition is invalid
347349
*/
348350
abstract protected function createNode();
351+
352+
/**
353+
* Set PathSeparator to use.
354+
*
355+
* @param string $separator
356+
*
357+
* @return $this
358+
*/
359+
public function setPathSeparator(string $separator)
360+
{
361+
if ($this instanceof ParentNodeDefinitionInterface) {
362+
if (method_exists($this, 'getChildNodeDefinitions')) {
363+
foreach ($this->getChildNodeDefinitions() as $child) {
364+
$child->setPathSeparator($separator);
365+
}
366+
} else {
367+
@trigger_error('Passing a ParentNodeDefinitionInterface without getChildNodeDefinitions() is deprecated since version 4.1 and will be removed in 5.0.', E_USER_DEPRECATED);
368+
}
369+
}
370+
371+
$this->pathSeparator = $separator;
372+
373+
return $this;
374+
}
349375
}

0 commit comments

Comments
 (0)