Chris@0: link = $link; Chris@0: $this->hasChildren = $has_children; Chris@0: $this->depth = $depth; Chris@0: $this->subtree = $subtree; Chris@0: $this->inActiveTrail = $in_active_trail; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Counts all menu links in the current subtree. Chris@0: * Chris@0: * @return int Chris@0: * The number of menu links in this subtree (one plus the number of menu Chris@0: * links in all descendants). Chris@0: */ Chris@0: public function count() { Chris@0: $sum = function ($carry, MenuLinkTreeElement $element) { Chris@0: return $carry + $element->count(); Chris@0: }; Chris@0: return 1 + array_reduce($this->subtree, $sum); Chris@0: } Chris@0: Chris@0: }