Skip to content

Commit f17f567

Browse files
committed
Make sur AttributeNode attributes are used when exporting to a Graph.
1 parent a3cef6e commit f17f567

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

spec/drupol/phptree/Exporter/GraphSpec.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use drupol\phptree\Exporter\Graph;
88
use drupol\phptree\Importer\Text;
9+
use drupol\phptree\Node\AttributeNode;
910
use drupol\phptree\Node\ValueNode;
1011
use Graphp\GraphViz\GraphViz;
1112
use PhpSpec\ObjectBehavior;
@@ -36,7 +37,7 @@ public function getMatchers(): array
3637

3738
public function it_can_generate_a_graph()
3839
{
39-
$tree = new ValueNode('root');
40+
$tree = new AttributeNode(['graphviz.label' => 'root']);
4041
$child1 = new ValueNode('child1');
4142
$child2 = new ValueNode('child2');
4243
$child3 = new ValueNode('child3');

src/Exporter/Graph.php

+7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace drupol\phptree\Exporter;
66

7+
use drupol\phptree\Node\AttributeNodeInterface;
78
use drupol\phptree\Node\NodeInterface;
89
use drupol\phptree\Node\ValueNodeInterface;
910
use Fhaculty\Graph\Graph as OriginalGraph;
@@ -61,6 +62,12 @@ protected function createVertex(NodeInterface $node): Vertex
6162
if ($node instanceof ValueNodeInterface) {
6263
$vertex->setAttribute('graphviz.label', $node->getValue());
6364
}
65+
66+
if ($node instanceof AttributeNodeInterface) {
67+
foreach ($node->getAttributes() as $key => $value) {
68+
$vertex->setAttribute($key, $value);
69+
}
70+
}
6471
}
6572

6673
return $this->getGraph()->getVertex($vertexId);

0 commit comments

Comments
 (0)