Skip to content

Commit 36f7be7

Browse files
committed
Let user customize the Ascii exporter.
1 parent 4c23013 commit 36f7be7

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/Exporter/Ascii.php

+31-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function export(NodeInterface $node): string
5757
*/
5858
private function doExportAsArray(NodeInterface $node): array
5959
{
60-
if (!($node instanceof ValueNodeInterface)) {
60+
if (!$this->isValidNode($node)) {
6161
throw new \InvalidArgumentException('Must implements ValueNodeInterface');
6262
}
6363

@@ -68,7 +68,35 @@ private function doExportAsArray(NodeInterface $node): array
6868
}
6969

7070
return [] === $children ?
71-
[$node->getValue()] :
72-
[$node->getValue(), $children];
71+
[$this->getNodeRepresentation($node)] :
72+
[$this->getNodeRepresentation($node), $children];
73+
}
74+
75+
/**
76+
* Check if a node is valid for being exported.
77+
*
78+
* @param \drupol\phptree\Node\NodeInterface $node
79+
* The node.
80+
*
81+
* @return bool
82+
* True if it's valid, false otherwise.
83+
*/
84+
protected function isValidNode(NodeInterface $node): bool
85+
{
86+
return $node instanceof ValueNodeInterface;
87+
}
88+
89+
/**
90+
* Get a string representation of the node.
91+
*
92+
* @param \drupol\phptree\Node\NodeInterface $node
93+
* The node.
94+
*
95+
* @return string
96+
* The node representation.
97+
*/
98+
protected function getNodeRepresentation(NodeInterface $node): string
99+
{
100+
return $node->getValue();
73101
}
74102
}

0 commit comments

Comments
 (0)