|
2 | 2 |
|
3 | 3 | declare(strict_types = 1);
|
4 | 4 |
|
5 |
| -namespace drupol\phptree\Render; |
| 5 | +namespace drupol\phptree\Converter; |
6 | 6 |
|
7 | 7 | use drupol\phptree\Node\NodeInterface;
|
| 8 | +use drupol\phptree\Visitor\BreadthFirstVisitor; |
8 | 9 | use drupol\phptree\Visitor\VisitorInterface;
|
9 |
| -use Fhaculty\Graph\Graph; |
10 |
| -use Graphp\GraphViz\GraphViz as OriginalGraphViz; |
| 10 | +use Fhaculty\Graph\Graph as OriginalGraph; |
11 | 11 |
|
12 | 12 | /**
|
13 |
| - * Class GraphViz |
| 13 | + * Class Graph |
14 | 14 | */
|
15 |
| -class GraphViz implements RendererInterface |
| 15 | +class Graph implements ConverterInterface |
16 | 16 | {
|
17 |
| - /** |
18 |
| - * @var \drupol\phptree\Visitor\VisitorInterface |
19 |
| - */ |
20 |
| - private $visitor; |
21 |
| - |
22 | 17 | /**
|
23 | 18 | * @var \Fhaculty\Graph\Graph
|
24 | 19 | */
|
25 | 20 | private $graph;
|
26 | 21 |
|
27 | 22 | /**
|
28 |
| - * @var \Graphp\GraphViz\GraphViz |
29 |
| - */ |
30 |
| - private $graphviz; |
31 |
| - |
32 |
| - /** |
33 |
| - * GraphViz constructor. |
34 |
| - * |
35 |
| - * @param \drupol\phptree\Visitor\VisitorInterface $visitor |
| 23 | + * @var \drupol\phptree\Visitor\VisitorInterface |
36 | 24 | */
|
37 |
| - public function __construct(VisitorInterface $visitor, Graph $graph, OriginalGraphViz $graphViz) |
38 |
| - { |
39 |
| - $this->visitor = $visitor; |
40 |
| - $this->graph = $graph; |
41 |
| - $this->graphviz = $graphViz; |
42 |
| - } |
| 25 | + private $visitor; |
43 | 26 |
|
44 | 27 | /**
|
45 |
| - * @param \drupol\phptree\Node\NodeInterface $node |
| 28 | + * Graph constructor. |
46 | 29 | *
|
47 |
| - * @return string |
| 30 | + * @param \Fhaculty\Graph\Graph $graph |
| 31 | + * @param \drupol\phptree\Visitor\VisitorInterface|null $visitor |
48 | 32 | */
|
49 |
| - public function render(NodeInterface $node): string |
| 33 | + public function __construct(OriginalGraph $graph = null, VisitorInterface $visitor = null) |
50 | 34 | {
|
51 |
| - return $this->graphviz->createScript($this->getGraph($node)); |
| 35 | + $this->graph = $graph ?? new OriginalGraph(); |
| 36 | + $this->visitor = $visitor ?? new BreadthFirstVisitor(); |
52 | 37 | }
|
53 | 38 |
|
54 | 39 | /**
|
55 | 40 | * @param \drupol\phptree\Node\NodeInterface $node
|
56 | 41 | *
|
57 | 42 | * @return \Fhaculty\Graph\Graph
|
58 | 43 | */
|
59 |
| - public function getGraph(NodeInterface $node): Graph |
| 44 | + public function convert(NodeInterface $node): OriginalGraph |
60 | 45 | {
|
61 | 46 | foreach ($this->visitor->traverse($node) as $node_visited) {
|
62 | 47 | /** @var int $hash */
|
|
0 commit comments