Menu parser
@param $items
@return static
425403
protected function parser($items)
    {
        return collect($items)->sortBy('sort')->map(function ($val, $name) {

            $children = $this->parser(array_get($val, 'children'));

            $url = array_get($val, 'url', array_get($val, 'uri') ? url($this->uri_prefix . '/' . array_get($val, 'uri')) : '');

            return collect(array_merge($val, [
                'name' => $name,
                'url' => $url,
                'children' => $children->isNotEmpty() ? $children : null
            ]))->filter();

        })->filter(function ($val) {

            if (!$val->has('children') && !$val->has('url')) return false;

            $user = $this->auth->user();
            $authority = array_get($val, 'authority');

            return !empty($val['name']) && (!$authority || $user->can(str_start($authority, 'admin.')));

        });
    }
819245
protected function _prepareItems($items)
    {
        if (is_integer($items)) {
            $id = $items;
            $cacheKey = "render({$id})";
            $items = static::cache($cacheKey);

            if ($items === null) {
                $items = TableRegistry::get('Menu.MenuLinks')
                    ->find('threaded')
                    ->where(['menu_id' => $id])
                    ->all();
                static::cache($cacheKey, $items);
            }
        } elseif (is_string($items)) {
            $slug = $items;
            $cacheKey = "render({$slug})";
            $items = static::cache($cacheKey);

            if ($items === null) {
                $items = [];
                $menu = TableRegistry::get('Menu.Menus')
                    ->find()
                    ->select(['id'])
                    ->where(['slug' => $slug])
                    ->first();

                if ($menu instanceof EntityInterface) {
                    $items = TableRegistry::get('Menu.MenuLinks')
                        ->find('threaded')
                        ->where(['menu_id' => $menu->id])
                        ->all();
                }
                static::cache($cacheKey, $items);
            }
        }

        return $items;
    }
548655
public function merge(MenuItemCollection $items)
    {
        foreach ($items->getItems() as $name => $item) {
            $this->set($name, $item);
        }

        return $this;
    }
1336052
private function _build_items(array $items)
	{
		foreach ($items as $key => $item) {
			$this->_items[$key] = new Element_Item($item, $this, $key);
		}

		return $this;
	}
295217
public static function items($menu = 'sidebar', $items = null)
    {
        if (!is_string($menu)) {
            throw new \UnexpectedValueException('Menu id is not a string');
        }

        if (!empty($items)) {
            self::$_items[$menu] = $items;
        }

        if (!array_key_exists($menu, self::$_items)) {
            Log::error('Invalid menu: ' . $menu);
            return [];
        }

        return self::$_items[$menu];
    }
42283
public function union($items): ArrayCollection
    {
        return new static(array_unique(array_merge($this->items, $this->itemsArray($items))));
    }
1133283
public function renderMenuPart($items)
    {
        $items = $this->normalizeItems($items, $hasActiveChild);

        $lines = '';
        foreach ($items as $i => $item) {
            Html::addCssClass($item['options'], 'item');
            if ($item['active']) {
                Html::addCssClass($item['options'], 'active');
            }

            if (isset($item['items'])) {
                Html::addCssClass($item['options'], 'ui simple dropdown');
                $item['label'] =
                    $item['label'] .
                    Elements::icon('dropdown') .
                    Html::tag('div', $this->renderMenuPart($item['items']), ['class' => 'menu']);

                $menu = $this->renderItem($item);
            } else {
                $menu = $this->renderItem($item);
            }
            $lines .= $menu;
        }
        return $lines;
    }
126602
protected static function dropdown($items, $htmlOptions = array())
    {
        TbArray::defaultValue('role', 'menu', $htmlOptions);
        self::addCssClass('dropdown-menu', $htmlOptions);
        return self::menu($items, $htmlOptions);
    }
1137458
public function setItems($items)
    {
        $orderItems = [];
        foreach ($items as $item) {
            if (is_array($item)) {
                $orderItems[] = new Item($item);
            } elseif (! ($item instanceof Item)) {
                throw new \InvalidArgumentException('Item should be an instance of ' . Item::class);
            }
        }

        return parent::setItems($orderItems);
    }
949270
public static function fromArray(array $items) : Interoperable
	{
		$obj = new static($items);
		foreach ($items as $key => $item) {
			$obj->__set($key, $item);
		}
		if (! empty($items['id'])) {
			$obj->setId($items[ 'id' ]);
		}
		return $obj;
	}
1173350
public static function make($items)
    {
        if (is_null($items)) {
            return new static;
        }

        if ($items instanceof Collection) {
            return $items;
        }

        return new static(is_array($items) ? $items : [$items]);
    }
221594
public function setItems(array $items)
    {
        $this->content = new HtmlElements();

        foreach ($items as $item) {
            $this->addItem($item);
        }

        return $this;
    }
244671
protected function resolveItems(array &$items)
    {
        $resolver = function ($property) {
            return $this->resolve($property) ?: $property;
        };

        for ($i = 0; $i < count($items); $i++) {
            $items[$i]->fill(array_map($resolver, $items[$i]->getProperties()));
        }
    }
105291
public function rawItems(array $items)
    {
        foreach ($items as $uri => $title) {
            list($title, $uri, $liAttr) = $this->fixData($uri, $title);
            $this->rawItem($title, $uri, $liAttr);
        }
        return $this;
    }
639066
protected function parseMenu($menus)
    {
        $menuItems = array();
        foreach ($menus as $name => $config) {
            if (!array_key_exists('route', $config) && !array_key_exists('uri', $config)) {
                throw new RuntimeException('"route" key must be set.');
            }

            $route = array_key_exists('route', $config) ? $config['route'] : $config['uri'];

            $menuItems[$route] = array();
            if (array_key_exists('child', $config)) {
                $menuItems[$route]['child'] = $this->parseMenu($config['child']);
            }

            $menuItems[$route]['label'] = $name;
            $menuItems[$route]['role'] = array_key_exists('role', $config) ? $config['role'] : 'ROLE_USER';
            $menuItems[$route]['icon'] = array_key_exists('icon', $config) ? $config['icon'] : 'fa-bars';
            $menuItems[$route]['extra'] = array_key_exists('extra', $config) ? $config['extra'] : '';
        }

        return $menuItems;
    }
780616
public function setItems(array $items) : self {
      foreach ($items as $item) {
        if (!($item instanceof Token)) {
          throw new \InvalidArgumentException('Expect array of tokens. Token[]');
        }
      }

      $this->items = $items;
      $this->rewind();
      return $this;
    }
461606
public function addContentItems($items = [])
    {
        // Loop on each item.
        collect($items)->each(function ($item) {
            // Add each content to the Container.
            $this->addSingleContentItem($item);
        });

        // Return object.
        return $this;
    }