Skip to content

Commit 2e54486

Browse files
committed
Add feature allowing change of Path Separator
1 parent beee423 commit 2e54486

19 files changed

+266
-25
lines changed

UPGRADE-4.1.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
UPGRADE FROM 4.0 to 4.1
2+
=======================
3+
4+
Config
5+
------
6+
7+
* Implementing `ParentNodeDefinitionInterface` without the `getChildNodeDefinitions()` method
8+
is deprecated and will be unsupported in 5.0.

UPGRADE-5.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UPGRADE FROM 4.x to 5.0
2+
=======================
3+
4+
Config
5+
------
6+
7+
* Added the `getChildNodeDefinitions()` method to `ParentNodeDefinitionInterface`.

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: 13 additions & 10 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,21 +34,24 @@ abstract class BaseNode implements NodeInterface
3234
protected $deprecationMessage = null;
3335
protected $equivalentValues = array();
3436
protected $attributes = array();
37+
protected $pathSeparator;
3538

3639
/**
37-
* @param string $name The name of the node
38-
* @param NodeInterface $parent The parent of this node
40+
* @param string $name The name of the node
41+
* @param NodeInterface $parent The parent of this node
42+
* @param string $pathSeparator The Path Separator that is used
3943
*
40-
* @throws \InvalidArgumentException if the name contains a period
44+
* @throws \InvalidArgumentException if the name contains path separator
4145
*/
42-
public function __construct($name, NodeInterface $parent = null)
46+
public function __construct($name, NodeInterface $parent = null, $pathSeparator = self::DEFAULT_PATH_SEPARATOR)
4347
{
44-
if (false !== strpos($name, '.')) {
45-
throw new \InvalidArgumentException('The name must not contain ".".');
48+
if (false !== strpos($name, $pathSeparator)) {
49+
throw new \InvalidArgumentException('The name must not contain "'.$pathSeparator.'".');
4650
}
4751

4852
$this->name = $name;
4953
$this->parent = $parent;
54+
$this->pathSeparator = $pathSeparator;
5055
}
5156

5257
public function setAttribute($key, $value)
@@ -233,13 +238,11 @@ public function getName()
233238
*/
234239
public function getPath()
235240
{
236-
$path = $this->name;
237-
238241
if (null !== $this->parent) {
239-
$path = $this->parent->getPath().'.'.$path;
242+
return $this->parent->getPath().$this->pathSeparator.$this->name;
240243
}
241244

242-
return $path;
245+
return $this->name;
243246
}
244247

245248
/**

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

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

410410
$this->validateConcreteNode($node);
411411

@@ -416,7 +416,7 @@ protected function createNode()
416416
$node->addChild($child->getNode());
417417
}
418418
} else {
419-
$node = new PrototypedArrayNode($this->name, $this->parent);
419+
$node = new PrototypedArrayNode($this->name, $this->parent, $this->pathSeparator);
420420

421421
$this->validatePrototypeNode($node);
422422

@@ -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($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

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

0 commit comments

Comments
 (0)