Refactored

This commit is contained in:
Kevin Frantz 2018-10-04 22:05:31 +02:00
parent ebf97e43d9
commit cde432a4b4
7 changed files with 35 additions and 31 deletions

View File

@ -0,0 +1,22 @@
<?php
namespace App\DBAL\Types;
use Fresh\DoctrineEnumBundle\DBAL\Types\AbstractEnumType;
/**
* Not integrated in the db. Just used for mapping.
* May it will be helpfull for tracking ;)
* @author kevinfrantz
*/
final class MenuEventType extends AbstractEnumType
{
public const USER = 'app.menu.topbar.user';
public const SOURCE = 'app.menu.source.user';
protected static $choices = [
self::USER => self::USER,
self::SOURCE => self::SOURCE,
];
}

View File

@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
* @author kevinfrantz
*
*/
abstract class AbstractMenuEvent extends Event
class MenuEvent extends Event
{
/**
* @var FactoryInterface

View File

@ -1,10 +0,0 @@
<?php
namespace App\Event\Menu\Subbar;
use App\Event\Menu\AbstractMenuEvent;
class SourceMenuEvent extends AbstractMenuEvent
{
public const EVENT = 'app.menu.source.user';
}

View File

@ -1,10 +0,0 @@
<?php
namespace App\Event\Menu\Topbar;
use App\Event\Menu\AbstractMenuEvent;
class UserMenuEvent extends AbstractMenuEvent
{
public const EVENT = 'app.menu.topbar.user';
}

View File

@ -2,12 +2,12 @@
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;
use App\Event\Menu\Subbar\SourceMenuEvent;
use App\Event\Menu\MenuEvent;
use App\DBAL\Types\MenuEventType;
class Menu
{
@ -35,7 +35,7 @@ class Menu
],
]);
$this->dispatcher->dispatch(SourceMenuEvent::EVENT, new SourceMenuEvent($this->factory, $menu, $request));
$this->dispatcher->dispatch(MenuEventType::SOURCE, new MenuEvent($this->factory, $menu, $request));
return $menu;
}
@ -48,7 +48,7 @@ class Menu
],
]);
$this->dispatcher->dispatch(UserMenuEvent::EVENT, new UserMenuEvent($this->factory, $menu, $request));
$this->dispatcher->dispatch(MenuEventType::USER, new MenuEvent($this->factory, $menu, $request));
return $menu;
}

View File

@ -2,11 +2,12 @@
namespace App\Subscriber;
use App\Event\Menu\Subbar\SourceMenuEvent;
use App\Event\Menu\MenuEvent;
use App\DBAL\Types\MenuEventType;
class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
{
public function onSourceMenuConfigure(SourceMenuEvent $event): void
public function onSourceMenuConfigure(MenuEvent $event): void
{
$menu = $event->getItem();
$menu->addChild($this->translator->trans('edit'), [
@ -33,7 +34,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
public static function getSubscribedEvents(): array
{
return [
SourceMenuEvent::EVENT => 'onSourceMenuConfigure',
MenuEventType::SOURCE => 'onSourceMenuConfigure',
];
}
}

View File

@ -2,11 +2,12 @@
namespace App\Subscriber;
use App\Event\Menu\Topbar\UserMenuEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Knp\Menu\ItemInterface;
use App\Event\Menu\MenuEvent;
use App\DBAL\Types\MenuEventType;
class UserMenuSubscriber implements EventSubscriberInterface
{
@ -26,7 +27,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
$this->translator = $translator;
}
public function onUserMenuConfigure(UserMenuEvent $event): void
public function onUserMenuConfigure(MenuEvent $event): void
{
$menu = $event->getItem();
$menu->addChild($this->translator->trans('start'), [
@ -89,7 +90,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
public static function getSubscribedEvents(): array
{
return [
UserMenuEvent::EVENT => 'onUserMenuConfigure',
MenuEventType::USER=> 'onUserMenuConfigure',
];
}
}