/** * Actually does the magic for presenting nodes. * * @param Cartalyst\NestedSets\Nodes\NodeInterface $node * @param string $format * @param string|Closure $attribute * @param int $depth * @return mixed */ public function recursivelyPresentAs(NodeInterface $node, $format, $attribute, $depth = 0, $includeNode = false) { $present = []; $node->findChildren($depth); foreach ($node->getChildren() as $child) { $extracted = $this->extractPresentable($child, $attribute); if ($child->getChildren()) { $present[$extracted] = $this->presentChildrenAs($child, 'array', $attribute, $depth, false); } else { $present[] = $extracted; } } if ($includeNode === true) { $extracted = $this->extractPresentable($node, $attribute); $present = [$extracted => $present]; } return $this->{'presentArrayAs' . ucfirst($format)}($present); }