File tree Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Expand file tree Collapse file tree 2 files changed +81
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,32 @@ public function dump(ConfigurationInterface $configuration)
33
33
return $ this ->dumpNode ($ configuration ->getConfigTreeBuilder ()->buildTree ());
34
34
}
35
35
36
+ public function dumpAtPath (ConfigurationInterface $ configuration , $ path )
37
+ {
38
+ $ rootNode = $ node = $ configuration ->getConfigTreeBuilder ()->buildTree ();
39
+
40
+ foreach (explode ('. ' , $ path ) as $ step ) {
41
+ if (!$ node instanceof ArrayNode) {
42
+ throw new \UnexpectedValueException (sprintf ('Unable to find node at path "%s.%s" ' , $ rootNode ->getName (), $ path ));
43
+ }
44
+
45
+ /** @var NodeInterface[] $children */
46
+ $ children = $ node instanceof PrototypedArrayNode ? $ this ->getPrototypeChildren ($ node ) : $ node ->getChildren ();
47
+
48
+ foreach ($ children as $ child ) {
49
+ if ($ child ->getName () === $ step ) {
50
+ $ node = $ child ;
51
+
52
+ continue 2 ;
53
+ }
54
+ }
55
+
56
+ throw new \UnexpectedValueException (sprintf ('Unable to find node at path "%s.%s" ' , $ rootNode ->getName (), $ path ));
57
+ }
58
+
59
+ return $ this ->dumpNode ($ node );
60
+ }
61
+
36
62
public function dumpNode (NodeInterface $ node )
37
63
{
38
64
$ this ->reference = '' ;
Original file line number Diff line number Diff line change @@ -25,6 +25,61 @@ public function testDumper()
25
25
$ this ->assertEquals ($ this ->getConfigurationAsString (), $ dumper ->dump ($ configuration ));
26
26
}
27
27
28
+ public function provideDumpAtPath ()
29
+ {
30
+ return array (
31
+ 'Regular node ' => array ('scalar_true ' , <<<EOL
32
+ scalar_true: true
33
+ EOL
34
+ ),
35
+ 'Array node ' => array ('array ' , <<<EOL
36
+ # some info
37
+ array:
38
+ child1: ~
39
+ child2: ~
40
+
41
+ # this is a long
42
+ # multi-line info text
43
+ # which should be indented
44
+ child3: ~ # Example: example setting
45
+ EOL
46
+ ),
47
+ 'Regular nested ' => array ('array.child2 ' , <<<EOL
48
+ child2: ~
49
+ EOL
50
+ ),
51
+ 'Prototype ' => array ('cms_pages.page ' , <<<EOL
52
+ # Prototype
53
+ page:
54
+
55
+ # Prototype
56
+ locale:
57
+ title: ~ # Required
58
+ path: ~ # Required
59
+ EOL
60
+ ),
61
+ 'Nested prototype ' => array ('cms_pages.page.locale ' , <<<EOL
62
+ # Prototype
63
+ locale:
64
+ title: ~ # Required
65
+ path: ~ # Required
66
+ EOL
67
+ ),
68
+ );
69
+ }
70
+
71
+ /**
72
+ * @dataProvider provideDumpAtPath
73
+ */
74
+ public function testDumpAtPath ($ path , $ expected )
75
+ {
76
+ $ configuration = new ExampleConfiguration ();
77
+
78
+ $ dumper = new YamlReferenceDumper ();
79
+
80
+ $ this ->assertSame (trim ($ expected ), trim ($ dumper ->dumpAtPath ($ configuration , $ path )));
81
+ }
82
+
28
83
private function getConfigurationAsString ()
29
84
{
30
85
return <<<'EOL'
You can’t perform that action at this time.
0 commit comments