From cde432a4b44de930e624c1efb454a820e1c272cc Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 4 Oct 2018 22:05:31 +0200 Subject: [PATCH] Refactored --- application/src/DBAL/Types/MenuEventType.php | 22 +++++++++++++++++++ .../{AbstractMenuEvent.php => MenuEvent.php} | 2 +- .../src/Event/Menu/Subbar/SourceMenuEvent.php | 10 --------- .../src/Event/Menu/Topbar/UserMenuEvent.php | 10 --------- application/src/Menu/Menu.php | 8 +++---- .../src/Subscriber/SourceMenuSubscriber.php | 7 +++--- .../src/Subscriber/UserMenuSubscriber.php | 7 +++--- 7 files changed, 35 insertions(+), 31 deletions(-) create mode 100644 application/src/DBAL/Types/MenuEventType.php rename application/src/Event/Menu/{AbstractMenuEvent.php => MenuEvent.php} (95%) delete mode 100644 application/src/Event/Menu/Subbar/SourceMenuEvent.php delete mode 100644 application/src/Event/Menu/Topbar/UserMenuEvent.php diff --git a/application/src/DBAL/Types/MenuEventType.php b/application/src/DBAL/Types/MenuEventType.php new file mode 100644 index 0000000..86a5991 --- /dev/null +++ b/application/src/DBAL/Types/MenuEventType.php @@ -0,0 +1,22 @@ + self::USER, + self::SOURCE => self::SOURCE, + ]; +} diff --git a/application/src/Event/Menu/AbstractMenuEvent.php b/application/src/Event/Menu/MenuEvent.php similarity index 95% rename from application/src/Event/Menu/AbstractMenuEvent.php rename to application/src/Event/Menu/MenuEvent.php index 8cee78a..59ff717 100644 --- a/application/src/Event/Menu/AbstractMenuEvent.php +++ b/application/src/Event/Menu/MenuEvent.php @@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\RequestStack; * @author kevinfrantz * */ -abstract class AbstractMenuEvent extends Event +class MenuEvent extends Event { /** * @var FactoryInterface diff --git a/application/src/Event/Menu/Subbar/SourceMenuEvent.php b/application/src/Event/Menu/Subbar/SourceMenuEvent.php deleted file mode 100644 index 5a99ba0..0000000 --- a/application/src/Event/Menu/Subbar/SourceMenuEvent.php +++ /dev/null @@ -1,10 +0,0 @@ -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; } diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php index 22a03a7..6d7b4a1 100644 --- a/application/src/Subscriber/SourceMenuSubscriber.php +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -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', ]; } } diff --git a/application/src/Subscriber/UserMenuSubscriber.php b/application/src/Subscriber/UserMenuSubscriber.php index 919c729..ac475f1 100644 --- a/application/src/Subscriber/UserMenuSubscriber.php +++ b/application/src/Subscriber/UserMenuSubscriber.php @@ -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', ]; } }