@@ -24,7 +24,7 @@ It also provides [4 trees traversals algorithm](https://en.wikipedia.org/wiki/Tr
24
24
* Pre order
25
25
* Breadth first
26
26
27
- And it provides Exporters and Importers for :
27
+ And it provides exporters and importers :
28
28
* Graph: Export a tree into a graph using the [ graphp/graphp] ( https://github.com/graphp/graph ) library.
29
29
* Text: Export a tree into a simple string.
30
30
@@ -55,22 +55,29 @@ declare(strict_types = 1);
55
55
use Graphp\GraphViz\GraphViz;
56
56
use drupol\phptree\Exporter\Graph;
57
57
use drupol\phptree\Node\ValueNode;
58
+ use drupol\phptree\Exporter\Text;
58
59
59
60
include './vendor/autoload.php';
60
61
62
+ // Create the root node.
61
63
$tree = new ValueNode('root', 2);
62
64
63
65
$nodes = [];
64
66
foreach (\range('A', 'Z') as $v) {
65
67
$nodes[] = new ValueNode($v);
66
68
}
67
69
70
+ // Add children to the root node.
68
71
$tree->add(...$nodes);
69
72
73
+ // Export to an image.
70
74
$graphViz = new GraphViz();
71
- $exporter = new Graph();
75
+ $graphExporter = new Graph();
76
+ $graphViz->display($graphExporter->export($tree));
72
77
73
- $graphViz->display($exporter->export($tree));
78
+ // Export to text.
79
+ $textExporter = new Text();
80
+ echo $textExporter->export($tree); // [root [A [C [G [O] [P]] [H [Q] [R]]] [D [I [S] [T]] [J [U] [V]]]] [B [E [K [W] [X]] [L [Y] [Z]]] [F [M] [N]]]]⏎
74
81
```
75
82
76
83
## Code quality, tests and benchmarks
0 commit comments