Example #1
0
 /**
  * Walk a JSON tree to import a hierarchy of menus
  */
 private static function importRecurse($entry, $depth)
 {
     if (isset($entry->menu)) {
         $entry = $entry->menu;
     }
     // Skip right past these
     if (!is_array($entry)) {
         $link = $entry->link;
         $href = $entry->href;
         if (is_string($href)) {
             return new \Tsugi\UI\MenuEntry($link, $href);
         }
         $submenu = self::importRecurse($href, $depth + 1);
         return new \Tsugi\UI\MenuEntry($link, $submenu);
     }
     $submenu = new \Tsugi\UI\Menu();
     foreach ($entry as $child) {
         $submenu->add(self::importRecurse($child, $depth + 1));
     }
     return $submenu;
 }