public function get($menu, array $path = array(), array $defaultRouteParams = array(), $link = false, array $extra = array())
    {
        if (!$menu instanceof ItemInterface) {
            if (null === $this->builder) {
                throw new \BadMethodCallException('A menu provider must be set to retrieve a menu');
            }

            $routeParams = array();
            if(isset($defaultRouteParams['_default'])) {
                $routeParams = $defaultRouteParams;
                unset($routeParams['_default']);
                $defaultRouteParams =  $defaultRouteParams['_default'];
            }
            if(isset($defaultRouteParams['_routes'])) {
                $routeParams = $defaultRouteParams['_routes'];
                unset($defaultRouteParams['_routes']);
            }

            $menu = $link
                ? $this->builder->createLink($menu, $defaultRouteParams, $extra)
                : $this->builder->createMenu($menu, $defaultRouteParams, $routeParams, $extra);

            if (!$menu instanceof ItemInterface) {
                throw new \LogicException(sprintf('The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.', $menuName));
            }
        }

        foreach ($path as $child) {
            $menu = $menu->getChild($child);
            if (null === $menu) {
                throw new \InvalidArgumentException(sprintf('The menu has no child named "%s"', $child));
            }
        }

        return $menu;
    }
public function get($menu, array $path = array(), array $defaultRouteParams = array(), $link = false, array $extra = array())
    {
        if (!$menu instanceof ItemInterface) {
            if (null === $this->builder) {
                throw new \BadMethodCallException('A menu provider must be set to retrieve a menu');
            }

            $routeParams = array();
            if(isset($defaultRouteParams['_default'])) {
                $routeParams = $defaultRouteParams;
                unset($routeParams['_default']);
                $defaultRouteParams =  $defaultRouteParams['_default'];
            }
            if(isset($defaultRouteParams['_routes'])) {
                $routeParams = $defaultRouteParams['_routes'];
                unset($defaultRouteParams['_routes']);
            }

            $menu = $link
                ? $this->builder->createLink($menu, $defaultRouteParams, $extra)
                : $this->builder->createMenu($menu, $defaultRouteParams, $routeParams, $extra);

            if (!$menu instanceof ItemInterface) {
                throw new \LogicException(sprintf('The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.', $menuName));
            }
        }

        foreach ($path as $child) {
            $menu = $menu->getChild($child);
            if (null === $menu) {
                throw new \InvalidArgumentException(sprintf('The menu has no child named "%s"', $child));
            }
        }

        return $menu;
    }
public function get ( $ menu , array $ path = array ( ) , array $ defaultRouteParams = array ( ) , $ link = false , array $ extra = array ( ) ) { if ( ! $ menu instanceof ItemInterface ) { if ( null === $ this -> builder ) { throw new \ BadMethodCallException ( 'A menu provider must be set to retrieve a menu' ) ; } $ routeParams = array ( ) ; if ( isset ( $ defaultRouteParams [ '_default' ] ) ) { $ routeParams = $ defaultRouteParams ; unset ( $ routeParams [ '_default' ] ) ; $ defaultRouteParams = $ defaultRouteParams [ '_default' ] ; } if ( isset ( $ defaultRouteParams [ '_routes' ] ) ) { $ routeParams = $ defaultRouteParams [ '_routes' ] ; unset ( $ defaultRouteParams [ '_routes' ] ) ; } $ menu = $ link ? $ this -> builder -> createLink ( $ menu , $ defaultRouteParams , $ extra ) : $ this -> builder -> createMenu ( $ menu , $ defaultRouteParams , $ routeParams , $ extra ) ; if ( ! $ menu instanceof ItemInterface ) { throw new \ LogicException ( sprintf ( 'The menu "%s" exists, but is not a valid menu item object. Check where you created the menu to be sure it returns an ItemInterface object.' , $ menuName ) ) ; } } foreach ( $ path as $ child ) { $ menu = $ menu -> getChild ( $ child ) ; if ( null === $ menu ) { throw new \ InvalidArgumentException ( sprintf ( 'The menu has no child named "%s"' , $ child ) ) ; } } return $ menu ; }
Retrieves item in the menu, eventually using the menu provider.

@param \Knp\Menu\ItemInterface|string $menu
@param array $path
@param array $routeParams
@param bool $link true - get single link, false - build all child items
@param array $extra

@return \Knp\Menu\ItemInterface

@throws \InvalidArgumentException when the path is invalid
@throws \BadMethodCallException when there is no menu provider and the menu is given by name
Retrieves item in the menu eventually using the menu provider .