Ejemplo n.º 1
0
 public function generate(MenuInterface $menu)
 {
     if ($route = $menu->getRoute()) {
         list($name, $parameters) = $route;
         return $this->router->generate($name, $parameters);
     }
     return $menu->getUri();
 }
Ejemplo n.º 2
0
 public function generate(MenuInterface $menu, $incSelf = true)
 {
     $tree = array();
     if ($incSelf) {
         $tree[$menu->getName()] = $menu;
     }
     if ($menu->hasChildren()) {
         $children = $menu->getChildren();
         uasort($children, function (MenuInterface $a, MenuInterface $b) {
             if ($a->getWeight() == $b->getWeight()) {
                 return 0;
             }
             return $a->getWeight() < $b->getWeight() ? 1 : -1;
         });
         foreach ($children as $child) {
             $tree = array_merge($tree, [$child->getName() => $child], $this->generate($child, false));
         }
     }
     return $tree;
 }