转menu为数组

@param array $menus

@return array
194394
protected function extractMenus(array $menus)
    {
        foreach ($menus as $key => $menu) {
            $menus[$key] = $menu->toArray();

            if ($menu->sub_button) {
                $menus[$key]['sub_button'] = $this->extractMenus($menu->sub_button);
            }
        }

        return $menus;
    }
290516
public static function createMenu(array $menu): MenuInterface
    {
        $menuInstance = new Menu();
        self::addToMenu($menuInstance, $menu);

        return $menuInstance;
    }
1036745
protected function getMenuOptions(array $settings)
    {
        $mapping = [
            'current_class' => 'currentClass',
            'first_class' => 'firstClass',
            'last_class' => 'lastClass',
            'safe_labels' => 'allow_safe_labels',
            'menu_template' => 'template',
        ];

        $options = [];

        foreach ($settings as $key => $value) {
            if (\array_key_exists($key, $mapping) && null !== $value) {
                $options[$mapping[$key]] = $value;
            }
        }

        return $options;
    }
334139
public function searchMenuEntryForKey($menuEntries, $key)
    {
        foreach ($menuEntries as $menuEntry) {
            if ($menuEntry->getKey() === $key) {
                return $menuEntry;
            } 
            
            if ($menuEntry->hasChildren()) {
                $result = $this->searchMenuEntryForKey($menuEntry->getChildren(), $key);
                
                if ($result !== false) {
                    return $result;
                }
            }
        }
        
        return false;
    }
919606
public function setIndividuationMenu($menus, $matchrule)
    {
        if ($menus instanceof Closure) {
            $menus = $menus($this);
        }

        if (!is_array($menus)) {
            $this->setError('子菜单必须是数组或者匿名函数返回数组');

            return false;
        }
        $menus = $this->extractMenus($menus);

        $data = [
            'button'    => $menus,
            'matchrule' => $matchrule,
        ];

        $res = $this->_post('addconditional', $data);

        return $res;
    }
651722
public function menu()
    {
        $url = Config::get('url.main_page');
        // 下载网页
        $response = $this->request('get', [$url]);
        $body = $this->checkAndThrow($response);

        // 分析网页
        $menu = [];
        $crawler = new Crawler($body);
        $crawler->filter('.sub')->each(function (Crawler $nodeUl, $i) use (&$menu) {
            $nodeMenu = $nodeUl->filter('li > a');
            if ($nodeMenu->count() > 0) {
                $nodeMenu->each(function (Crawler $nodeA, $i) use (&$menu) {
                    $urlRaw = $nodeA->attr('href');
                    if ($urlRaw != '#') {
                        $urlParsed = parse_url($urlRaw);
                        if (isset($urlParsed['path'])) {
                            $menu[] = [
                                'url_raw' => $urlRaw,
                                'url_base' => $urlParsed['path'],
                                'title' => $nodeA->html(),
                            ];
                        }
                    }
                });
            }
        });
        $info['student_number'] = $this->getUsername();
        $info['student_name'] = mb_substr($crawler->filter('#xhxm')->html(), 0, -2);

        return ['menu' => $menu, 'info' => $info];
    }
1344361
public static function parentID($menuLinkID)
    {
        $parentIDs = [];
        while($menuLinkID != null){
            $parentObj = MenuLink::all()->where('menuLinkID', $menuLinkID)->first();
            if ($parentObj) {
                $menuLinkID = $parentObj->parent;
                if ($menuLinkID) {
                    $parentIDs[] = $menuLinkID;
                }
            }
            if ($parentObj || !$menuLinkID) {
                $menuLinkID = null;
            }
        }
        return $parentIDs;
    }
1262099
public function createSubnavMenu($menuName, $classes = 'nav nav-tabs nav-stacked')
    {
        $menu = $this->factory->createItem('root');

        if ($classes) {
            $menu->setChildrenAttribute('class', $classes);
        }

        /** @var $mainMenu Menu */
        $menuIterator = $this->getSubMenu($menuName, 1);

        if (!$menuIterator) {
            return $menu;
        }

        $startDepth = 2;

        $menu = $this->createMenu($menu, $menuIterator, $startDepth);
        $this->showOnlyCurrentChildren($menu);
        $this->setRecursiveAttribute($menu, ['class' => 'nav nav-list']);

        return $menu;
    }
236670
public function menuLanguages(): ?Menu
    {
        $menu = new Menu(I18N::translate('Language'), '#', 'menu-language');

        foreach (I18N::activeLocales() as $locale) {
            $language_tag = $locale->languageTag();
            $class        = 'menu-language-' . $language_tag . (WT_LOCALE === $language_tag ? ' active' : '');
            $menu->addSubmenu(new Menu($locale->endonym(), '#', $class, [
                'onclick'       => 'return false;',
                'data-language' => $language_tag,
            ]));
        }

        if (count($menu->getSubmenus()) > 1) {
            return $menu;
        }

        return null;
    }
368426
public function menu($menu = null, $options = array())
	{
		$menu = $menu ?: $this->getDefaultMenu();

		// If the given menu has not been created before, we will create the instances
		// here and cache it so we can return it next time very quickly. If there is
		// already a menu created by this name, we'll just return that instance.
		if (!isset($this->menus[$menu]))
		{
			$this->menus[$menu] = $this->createMenu($menu, $options);
		}

		return $this->menus[$menu];
	}
1357827
public function getMenu($key)
	{
		if (strpos($key, '.') !== false) {
			return $this->getNested($key);
		}

		return array_key_exists($key, $this->menus) ? $this->menus[$key] : null;
	}
677264
public function menu($items, $default = null, $title = 'Choose an item')
    {
        if (isset($items[$default]) && strpos($title, '[') === false) {
            $title .= ' [default: ' . $items[$default] . ']';
        }

        $this->line(sprintf('%s: ', $title));

        $i = 1;
        $keys = array();

        foreach ($items as $key => $item) {
            $keys[$i] = $key;
            $this->line(sprintf('  %d. %s', $i, $item));
            $i++;
        }

        $selected = $this->in();

        if ($selected === '') {
            return $default;
        }

        if (isset($keys[$selected])) {
            return $keys[$selected];
        }

        return $selected;
    }
1315346
public function actionIndex()
    {
        $searchModel = new MenuSearch;
        $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams());

        if (Yii::$app->request->isAjax) {
            Yii::$app->getResponse()->format = 'json';
            $id = intval(Yii::$app->request->post('id'));
            $menuRows = MenuHelper::getMenu(Yii::$app->user->id, $id);
            $menus = [
                'status' => 'OK',
                'data' => null,
            ];
            if ($menuRows) {
                foreach ($menuRows as $key => $menuRow) {
                    if (isset($menuRow['items'])) {
                        $menus['data'][$key]['name'] = $menuRow['label'] . ' <span title="排序"> <i class="fa fa-sort"> </i> ' . $menuRow['order'] . '</span><div class="tree-actions"><a href="' . Url::toRoute(['update', 'id' => $menuRow['id']]) . '"><i class="fa fa-edit"></i></a> <a href="' . Url::toRoute(['delete', 'id' => $menuRow['id']]) . '" data-confirm="您确定要删除此项吗？" data-method="post" data-pjax="0"><i class="fa fa-trash-o"></i></a> <i class="fa fa-refresh"></i></div>';
                        $menus['data'][$key]['type'] = 'folder';
                        $menus['data'][$key]['additionalParameters'] = ['id' => $menuRow['id'], 'children' => true];
                    } else {
                        $menus['data'][$key]['name'] = $menuRow['label'] . ' <span title="排序"> <i class="fa fa-sort"> </i> ' . $menuRow['order'] . '</span><div class="tree-actions"><a href="' . Url::toRoute(['update', 'id' => $menuRow['id']]) . '"><i class="fa fa-edit"></i></a> <a href="' . Url::toRoute(['delete', 'id' => $menuRow['id']]) . '" data-confirm="您确定要删除此项吗？" data-method="post" data-pjax="0"><i class="fa fa-trash-o"></i></a> <i class="fa fa-refresh"></i></div>';
                        $menus['data'][$key]['type'] = 'item';
                        $menus['data'][$key]['additionalParameters'] = ['id' => $menuRow['id']];
                    }
                }
            }
            return $menus;
        }

        return $this->render('index', [
                'dataProvider' => $dataProvider,
                'searchModel' => $searchModel,
        ]);
    }
1121836
public function set($menus)
    {
        if ($menus instanceof Closure) {
            $menus = $menus($this);
        }

        if (!is_array($menus)) {
            $this->setError('子菜单必须是数组或者匿名函数返回数组');

            return false;
        }

        $menus = $this->extractMenus($menus);

        $data = ['button' => $menus];

        $res = $this->_post('create', $data);

        return $res;
    }
354072
protected function getAllMenus()
    {
        if (!empty(self::$menus)) {
            return self::$menus;
        }

        $components = PluginManager::getInstance()->findComponents('Menu', 'Piwik\\Plugin\\Menu');

        self::$menus = array();
        foreach ($components as $component) {
            self::$menus[] = StaticContainer::get($component);
        }

        return self::$menus;
    }
1018386
public function render(array $options = []): string
    {
        $html = $this->format['menuStart'];
        $html .= !empty($options['title']) ? $options['title'] : '';

        /**
         * @var MenuItemInterface $menuItem
         */
        foreach ($this->menu->getMenuItems() as $menuItem) {
            if ($menuItem->isEnabled()) {
                $html .= $this->renderMenuItem($menuItem);
            }
        }
        $html .= $this->format['menuEnd'];

        return $html;
    }
1152614
private function displayXML($menus)
    {
        $treeList = [];
        $manager  = $this->getTreeManager();

        /** @var \MakinaCorpus\Umenu\Menu $menu */
        foreach ($menus as $menu) {
            $tree = $manager->buildTree($menu->getId(), true);
            if (!$tree->isEmpty()) {
                $treeList[] = $tree;
            }
        }

        $output = $this->renderView('@ucms_seo/views/sitemap.xml.twig', ['menus_tree' => $treeList]);

        return new Response($output, 200, ['content-type' => 'application/xml']);
    }