src/UI/MenuSet.php
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;
    }
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;
    }
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 ; }
Walk a JSON tree to import a hierarchy of menus
Walk a JSON tree to import a hierarchy of menus