@@ -96,11 +96,12 @@ The above code will output the following tree:
96
96
└── templates
97
97
└── base.html.twig
98
98
99
- Building and Rendering a Tree
100
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
+ Building a Tree Programmatically
100
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101
101
102
- You can build a tree by creating a new instance of the
103
- :class: `Symfony\\ Component\\ Console\\ Helper\\ Tree ` class and adding nodes to it::
102
+ If you don't know the tree elements beforehand, you can build the tree programmatically
103
+ by creating a new instance of the :class: `Symfony\\ Component\\ Console\\ Helper\\ Tree `
104
+ class and adding nodes to it::
104
105
105
106
use Symfony\Component\Console\Helper\TreeHelper;
106
107
use Symfony\Component\Console\Helper\TreeNode;
@@ -129,20 +130,28 @@ This example outputs:
129
130
└── tests/
130
131
└── Functional/
131
132
133
+ If you prefer, you can build the array of elements programmatically and then
134
+ create and render the tree like this::
135
+
136
+ $tree = TreeHelper::createTree($io, null, $array);
137
+ $tree->render();
138
+
139
+ You can also build part of the tree from an array and then add other nodes::
140
+
141
+ $node = TreeNode::fromValues($array)
142
+ $node->addChild('templates');
143
+ // ...
144
+ $tree = TreeHelper::createTree($io, $node);
145
+ $tree->render();
146
+
132
147
Customizing the Tree Style
133
148
--------------------------
134
149
135
150
Built-in Tree Styles
136
151
~~~~~~~~~~~~~~~~~~~~
137
152
138
153
The tree helper provides a few built-in styles that you can use to customize the
139
- output of the tree::
140
-
141
- use Symfony\Component\Console\Helper\TreeStyle;
142
- // ...
143
-
144
- $tree = TreeHelper::createTree($io, $node, [], TreeStyle::compact());
145
- $tree->render();
154
+ output of the tree.
146
155
147
156
**Default **::
148
157
@@ -165,7 +174,7 @@ This outputs:
165
174
└── templates
166
175
└── base.html.twig
167
176
168
- **Box **:
177
+ **Box **::
169
178
170
179
TreeHelper::createTree($io, $node, [], TreeStyle::box());
171
180
@@ -270,7 +279,7 @@ This outputs:
270
279
. templates
271
280
. base.html.twig
272
281
273
- **Rounded **:
282
+ **Rounded **::
274
283
275
284
TreeHelper::createTree($io, $node, [], TreeStyle::rounded());
276
285
0 commit comments