<commit_before><?php
/**
 * MenuEventListener.php
 *
 * @since 08/05/15
 * @author gseidel
 */

namespace esperanto\AdminBundle\EventListener;

use esperanto\AdminBundle\Menu\MenuEvent;
use Knp\Menu\FactoryInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class MenuEventListener
{
    /**
     * @var boolean
     */
    protected $permissionCheck;

    /**
     * @var AuthorizationCheckerInterface
     */
    protected $authorizationChecker;

    /**
     * @var FactoryInterface
     */
    protected $factory;

    /**
     * @var array
     */
    protected $menu;

    /**
     * @var RequestStack
     */
    protected $stack;

    public function __construct($permissionCheck, AuthorizationCheckerInterface $authorizationChecker, FactoryInterface $factory, $menu, RequestStack $stack)
    {
        $this->permissionCheck = $permissionCheck;
        $this->authorizationChecker = $authorizationChecker;
        $this->factory = $factory;
        $this->menu = $menu;
        $this->stack = $stack;
    }

    public function onMenu(MenuEvent $event)
    {
        $menu = $event->getMenu();
        foreach($menu->getChildren() as $child) {
            /** @var $child ItemInterface */
            if($this->permissionCheck) {
                $role = $this->menu[$child->getName()]['role'];
                if(!$this->authorizationChecker->isGranted($role)) {
                    $child->setDisplay(false);
                }
            }
            $this->addClass($child);
            $this->addCurrent($child);
        }
        $this->addLogout($menu);
    }

    public function addClass(ItemInterface $menu)
    {
        $menu->setAttribute('class', sprintf('menu-icon-%s', $menu->getName()));
    }

    public function addCurrent(ItemInterface $menu)
    {
        $currentRoute = $this->stack->getMasterRequest()->get('_route');
        $route = $this->menu[$menu->getName()]['route'];
        if($currentRoute == $route) {
            $menu->setCurrent(true);
        }
    }

    public function addLogout(ItemInterface $menu)
    {
        $logout = $this->factory->createItem('logout', array(
            'route' => 'fos_user_security_logout'
        ));
        $logout->setLabel('label.logout');
        $menu->addChild($logout);
    }
}<commit_msg>bugfix missing menu logout css class<commit_after><?php
/**
 * MenuEventListener.php
 *
 * @since 08/05/15
 * @author gseidel
 */

namespace esperanto\AdminBundle\EventListener;

use esperanto\AdminBundle\Menu\MenuEvent;
use Knp\Menu\FactoryInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class MenuEventListener
{
    /**
     * @var boolean
     */
    protected $permissionCheck;

    /**
     * @var AuthorizationCheckerInterface
     */
    protected $authorizationChecker;

    /**
     * @var FactoryInterface
     */
    protected $factory;

    /**
     * @var array
     */
    protected $menu;

    /**
     * @var RequestStack
     */
    protected $stack;

    public function __construct($permissionCheck, AuthorizationCheckerInterface $authorizationChecker, FactoryInterface $factory, $menu, RequestStack $stack)
    {
        $this->permissionCheck = $permissionCheck;
        $this->authorizationChecker = $authorizationChecker;
        $this->factory = $factory;
        $this->menu = $menu;
        $this->stack = $stack;
    }

    public function onMenu(MenuEvent $event)
    {
        $menu = $event->getMenu();
        foreach($menu->getChildren() as $child) {
            /** @var $child ItemInterface */
            if($this->permissionCheck) {
                $role = $this->menu[$child->getName()]['role'];
                if(!$this->authorizationChecker->isGranted($role)) {
                    $child->setDisplay(false);
                }
            }
            $this->addClass($child);
            $this->addCurrent($child);
        }
        $this->addLogout($menu);
    }

    public function addClass(ItemInterface $menu)
    {
        $menu->setAttribute('class', sprintf('menu-icon-%s', $menu->getName()));
    }

    public function addCurrent(ItemInterface $menu)
    {
        $currentRoute = $this->stack->getMasterRequest()->get('_route');
        $route = $this->menu[$menu->getName()]['route'];
        if($currentRoute == $route) {
            $menu->setCurrent(true);
        }
    }

    public function addLogout(ItemInterface $menu)
    {
        $logout = $this->factory->createItem('logout', array(
            'route' => 'fos_user_security_logout'
        ));
        $logout->setLabel('label.logout');
        $logout->setAttribute('class', 'menu-icon-logout');
        $menu->addChild($logout);
    }
}
{'fraction_non_alphanumeric': 0.1449067431850789, 'fraction_numerical': 0.0024595203935232628, 'mean_word_length': 2.4782608695652173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 62, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5450203', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1375, 'n_words': 225}