47 lines
1.0 KiB
PHP
Raw Normal View History

<?php
2018-09-12 23:25:22 +03:00
// src/Menu/Menu.php
namespace App\Menu;
use App\Event\Menu\Topbar\UserMenuEvent;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\RequestStack;
class Menu
{
/**
* @var EventDispatcherInterface
*/
private $dispatcher;
2018-09-12 23:25:22 +03:00
/**
* @var FactoryInterface
*/
private $factory;
2018-09-12 23:25:22 +03:00
public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->factory = $factory;
}
2018-09-12 23:25:22 +03:00
public function userTopbar(RequestStack $request): ItemInterface
{
2018-09-12 23:25:22 +03:00
$menu = $this->factory->createItem('root', [
'childrenAttributes' => [
'class' => 'navbar-nav mr-auto',
],
]);
$this->dispatcher->dispatch(
UserMenuEvent::EVENT,
new UserMenuEvent($this->factory, $menu, $request)
);
2018-09-12 23:25:22 +03:00
return $menu;
2018-09-12 23:25:22 +03:00
}
}