Refactored menu events

This commit is contained in:
Kevin Frantz 2018-10-04 21:40:07 +02:00
parent fd65859572
commit ebf97e43d9
3 changed files with 66 additions and 103 deletions

View File

@ -0,0 +1,61 @@
<?php
namespace App\Event\Menu;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\RequestStack;
/**
*
* @author kevinfrantz
*
*/
abstract class AbstractMenuEvent extends Event
{
/**
* @var FactoryInterface
*/
private $factory;
/**
* @var ItemInterface
*/
private $item;
/**
* @var RequestStack
*/
private $request;
public function __construct(FactoryInterface $factory, ItemInterface $item, RequestStack $request)
{
$this->factory = $factory;
$this->item = $item;
$this->request = $request;
}
/**
* @return FactoryInterface
*/
public function getFactory(): FactoryInterface
{
return $this->factory;
}
/**
* @return ItemInterface
*/
public function getItem(): ItemInterface
{
return $this->item;
}
/**
* @return RequestStack
*/
public function getRequest(): RequestStack
{
return $this->request;
}
}

View File

@ -2,58 +2,9 @@
namespace App\Event\Menu\Subbar;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Event\Menu\AbstractMenuEvent;
class SourceMenuEvent extends Event
class SourceMenuEvent extends AbstractMenuEvent
{
public const EVENT = 'app.menu.source.user';
/**
* @var FactoryInterface
*/
private $factory;
/**
* @var ItemInterface
*/
private $item;
/**
* @var RequestStack
*/
private $request;
public function __construct(FactoryInterface $factory, ItemInterface $item, RequestStack $request)
{
$this->factory = $factory;
$this->item = $item;
$this->request = $request;
}
/**
* @return FactoryInterface
*/
public function getFactory(): FactoryInterface
{
return $this->factory;
}
/**
* @return ItemInterface
*/
public function getItem(): ItemInterface
{
return $this->item;
}
/**
* @return RequestStack
*/
public function getRequest(): RequestStack
{
return $this->request;
}
}

View File

@ -2,58 +2,9 @@
namespace App\Event\Menu\Topbar;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\HttpFoundation\RequestStack;
use App\Event\Menu\AbstractMenuEvent;
class UserMenuEvent extends Event
class UserMenuEvent extends AbstractMenuEvent
{
public const EVENT = 'app.menu.topbar.user';
/**
* @var FactoryInterface
*/
private $factory;
/**
* @var ItemInterface
*/
private $item;
/**
* @var RequestStack
*/
private $request;
public function __construct(FactoryInterface $factory, ItemInterface $item, RequestStack $request)
{
$this->factory = $factory;
$this->item = $item;
$this->request = $request;
}
/**
* @return FactoryInterface
*/
public function getFactory(): FactoryInterface
{
return $this->factory;
}
/**
* @return ItemInterface
*/
public function getItem(): ItemInterface
{
return $this->item;
}
/**
* @return RequestStack
*/
public function getRequest(): RequestStack
{
return $this->request;
}
}