55use Matthias \SymfonyConfigTest \Partial \Exception \ChildIsNotAnArrayNode ;
66use Matthias \SymfonyConfigTest \Partial \Exception \UndefinedChildNode ;
77use Symfony \Component \Config \Definition \ArrayNode ;
8+ use Symfony \Component \Config \Definition \NodeInterface ;
9+ use Symfony \Component \Config \Definition \PrototypedArrayNode ;
810
911class PartialNode
1012{
13+ /**
14+ * @var \ReflectionProperty
15+ */
1116 private static $ nodeChildrenProperty ;
1217
18+ /**
19+ * @var \ReflectionProperty
20+ */
21+ private static $ nodePrototypeProperty ;
22+
1323 /**
1424 * Provide an ArrayNode instance (e.g. the root node created by a TreeBuilder) and a path that is relevant to you,
1525 * e.g. "dbal.connections": this will strip every node that is not contained in the given path (e.g. the "orm" node
@@ -60,8 +70,18 @@ public static function excludeEverythingNotInPath(ArrayNode $node, array $path =
6070 self ::excludeEverythingNotInPath ($ nextNode , $ path );
6171 }
6272
73+ /**
74+ * @param ArrayNode $node
75+ * @param string $childNodeName
76+ *
77+ * @return NodeInterface
78+ */
6379 private static function childNode (ArrayNode $ node , $ childNodeName )
6480 {
81+ if ($ node instanceof PrototypedArrayNode && '* ' === $ childNodeName ) {
82+ return self ::nodePrototypeProperty ()->getValue ($ node );
83+ }
84+
6585 $ children = self ::nodeChildrenProperty ()->getValue ($ node );
6686
6787 if (!isset ($ children [$ childNodeName ])) {
@@ -74,6 +94,9 @@ private static function childNode(ArrayNode $node, $childNodeName)
7494 return $ children [$ childNodeName ];
7595 }
7696
97+ /**
98+ * @return \ReflectionProperty
99+ */
77100 private static function nodeChildrenProperty ()
78101 {
79102 if (!isset (self ::$ nodeChildrenProperty )) {
@@ -86,4 +109,20 @@ private static function nodeChildrenProperty()
86109
87110 return self ::$ nodeChildrenProperty ;
88111 }
112+
113+ /**
114+ * @return \ReflectionProperty
115+ */
116+ private static function nodePrototypeProperty ()
117+ {
118+ if (!isset (self ::$ nodePrototypeProperty )) {
119+ self ::$ nodePrototypeProperty = new \ReflectionProperty (
120+ 'Symfony\Component\Config\Definition\PrototypedArrayNode ' ,
121+ 'prototype '
122+ );
123+ self ::$ nodePrototypeProperty ->setAccessible (true );
124+ }
125+
126+ return self ::$ nodePrototypeProperty ;
127+ }
89128}
0 commit comments