This commit is contained in:
Kevin Frantz
2018-09-06 09:44:29 +02:00
parent f86b9a0f75
commit 36b9020c01
11 changed files with 301 additions and 3 deletions

View File

@@ -0,0 +1,42 @@
<?php
// 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;
/**
* @var FactoryInterface
*/
private $factory;
public function __construct(FactoryInterface $factory, EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
$this->factory = $factory;
}
public function userTopbar(RequestStack $request): ItemInterface
{
$menu = $this->factory->createItem('root');
$this->dispatcher->dispatch(
UserMenuEvent::EVENT,
new UserMenuEvent($this->factory, $menu, $request)
);
return $menu;
}
}