/** * @param Collection $menuCollection * @return PageMenuNode */ public static function buildTree($menuCollection) { $tree = new self(); foreach ($menuCollection as $menuItem) { $route = $menuItem->getParentRoute(); $node = $tree->findByRoute($route); if ($node) { $node->addChild(new self($menuItem)); } } return $tree; }