Skip to content

Commit

Permalink
Let user customize the Ascii exporter.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Jun 27, 2019
1 parent 4c23013 commit 36f7be7
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Exporter/Ascii.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function export(NodeInterface $node): string
*/
private function doExportAsArray(NodeInterface $node): array
{
if (!($node instanceof ValueNodeInterface)) {
if (!$this->isValidNode($node)) {
throw new \InvalidArgumentException('Must implements ValueNodeInterface');
}

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

return [] === $children ?
[$node->getValue()] :
[$node->getValue(), $children];
[$this->getNodeRepresentation($node)] :
[$this->getNodeRepresentation($node), $children];
}

/**
* Check if a node is valid for being exported.
*
* @param \drupol\phptree\Node\NodeInterface $node
* The node.
*
* @return bool
* True if it's valid, false otherwise.
*/
protected function isValidNode(NodeInterface $node): bool
{
return $node instanceof ValueNodeInterface;
}

/**
* Get a string representation of the node.
*
* @param \drupol\phptree\Node\NodeInterface $node
* The node.
*
* @return string
* The node representation.
*/
protected function getNodeRepresentation(NodeInterface $node): string
{
return $node->getValue();
}
}

0 comments on commit 36f7be7

Please sign in to comment.