src/Zicht/Bundle/MenuBundle/Twig/Extension.php
public function current($item, $level = null)
    {
        if (is_null($item)) {
            return null;
        }

        if (!$item instanceof MenuItem) {
            throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
        }

        /** @var MenuItem $child */
        foreach ($item->getChildren() as $child) {
            if (
                (null !== $this->matcher && $this->matcher->isAncestor($child))
             || (null === $this->matcher && $child->isCurrentAncestor())
            ) {
                if ($level !== null and $level == $child->getLevel()) {
                    return $child;
                }

                return $this->current($child);
            }

            if (
                (null !== $this->matcher && $this->matcher->isCurrent($child))
             || (null === $this->matcher && $child->isCurrent())
            ) {
                return $child;
            }
        }

        return null;
    }
public function current($item, $level = null)
    {
        if (is_null($item)) {
            return null;
        }

        if (!$item instanceof MenuItem) {
            throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
        }

        /** @var MenuItem $child */
        foreach ($item->getChildren() as $child) {
            if (
                (null !== $this->matcher && $this->matcher->isAncestor($child))
             || (null === $this->matcher && $child->isCurrentAncestor())
            ) {
                if ($level !== null and $level == $child->getLevel()) {
                    return $child;
                }

                return $this->current($child);
            }

            if (
                (null !== $this->matcher && $this->matcher->isCurrent($child))
             || (null === $this->matcher && $child->isCurrent())
            ) {
                return $child;
            }
        }

        return null;
    }
public function current ( $ item , $ level = null ) { if ( is_null ( $ item ) ) { return null ; } if ( ! $ item instanceof MenuItem ) { throw new \ UnexpectedValueException ( sprintf ( '$ITEM must be \Knp\Menu\MenuItem not "%s"' , get_class ( $ item ) ) ) ; } /** @var MenuItem $child */ foreach ( $ item -> getChildren ( ) as $ child ) { if ( ( null !== $ this -> matcher && $ this -> matcher -> isAncestor ( $ child ) ) || ( null === $ this -> matcher && $ child -> isCurrentAncestor ( ) ) ) { if ( $ level !== null and $ level == $ child -> getLevel ( ) ) { return $ child ; } return $ this -> current ( $ child ) ; } if ( ( null !== $ this -> matcher && $ this -> matcher -> isCurrent ( $ child ) ) || ( null === $ this -> matcher && $ child -> isCurrent ( ) ) ) { return $ child ; } } return null ; }
Returns the current menu item given a root menu item

@param MenuItem|null $item
@param int $level
@return MenuItem|null
Returns the current menu item given a root menu item