mirror of
https://github.com/kevinveenbirkenbach/infinito.git
synced 2025-01-09 14:07:25 +01:00
Refactored
This commit is contained in:
parent
ebf97e43d9
commit
cde432a4b4
22
application/src/DBAL/Types/MenuEventType.php
Normal file
22
application/src/DBAL/Types/MenuEventType.php
Normal 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,
|
||||||
|
];
|
||||||
|
}
|
@ -11,7 +11,7 @@ use Symfony\Component\HttpFoundation\RequestStack;
|
|||||||
* @author kevinfrantz
|
* @author kevinfrantz
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
abstract class AbstractMenuEvent extends Event
|
class MenuEvent extends Event
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var FactoryInterface
|
* @var FactoryInterface
|
@ -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';
|
|
||||||
}
|
|
@ -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';
|
|
||||||
}
|
|
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Menu;
|
namespace App\Menu;
|
||||||
|
|
||||||
use App\Event\Menu\Topbar\UserMenuEvent;
|
|
||||||
use Knp\Menu\FactoryInterface;
|
use Knp\Menu\FactoryInterface;
|
||||||
use Knp\Menu\ItemInterface;
|
use Knp\Menu\ItemInterface;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
use Symfony\Component\HttpFoundation\RequestStack;
|
use Symfony\Component\HttpFoundation\RequestStack;
|
||||||
use App\Event\Menu\Subbar\SourceMenuEvent;
|
use App\Event\Menu\MenuEvent;
|
||||||
|
use App\DBAL\Types\MenuEventType;
|
||||||
|
|
||||||
class Menu
|
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;
|
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;
|
return $menu;
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Subscriber;
|
namespace App\Subscriber;
|
||||||
|
|
||||||
use App\Event\Menu\Subbar\SourceMenuEvent;
|
use App\Event\Menu\MenuEvent;
|
||||||
|
use App\DBAL\Types\MenuEventType;
|
||||||
|
|
||||||
class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
|
class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
|
||||||
{
|
{
|
||||||
public function onSourceMenuConfigure(SourceMenuEvent $event): void
|
public function onSourceMenuConfigure(MenuEvent $event): void
|
||||||
{
|
{
|
||||||
$menu = $event->getItem();
|
$menu = $event->getItem();
|
||||||
$menu->addChild($this->translator->trans('edit'), [
|
$menu->addChild($this->translator->trans('edit'), [
|
||||||
@ -33,7 +34,7 @@ class SourceMenuSubscriber extends AbstractEntityMenuSubscriber
|
|||||||
public static function getSubscribedEvents(): array
|
public static function getSubscribedEvents(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
SourceMenuEvent::EVENT => 'onSourceMenuConfigure',
|
MenuEventType::SOURCE => 'onSourceMenuConfigure',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Subscriber;
|
namespace App\Subscriber;
|
||||||
|
|
||||||
use App\Event\Menu\Topbar\UserMenuEvent;
|
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||||
use Symfony\Component\Translation\TranslatorInterface;
|
use Symfony\Component\Translation\TranslatorInterface;
|
||||||
use Knp\Menu\ItemInterface;
|
use Knp\Menu\ItemInterface;
|
||||||
|
use App\Event\Menu\MenuEvent;
|
||||||
|
use App\DBAL\Types\MenuEventType;
|
||||||
|
|
||||||
class UserMenuSubscriber implements EventSubscriberInterface
|
class UserMenuSubscriber implements EventSubscriberInterface
|
||||||
{
|
{
|
||||||
@ -26,7 +27,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
|||||||
$this->translator = $translator;
|
$this->translator = $translator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onUserMenuConfigure(UserMenuEvent $event): void
|
public function onUserMenuConfigure(MenuEvent $event): void
|
||||||
{
|
{
|
||||||
$menu = $event->getItem();
|
$menu = $event->getItem();
|
||||||
$menu->addChild($this->translator->trans('start'), [
|
$menu->addChild($this->translator->trans('start'), [
|
||||||
@ -89,7 +90,7 @@ class UserMenuSubscriber implements EventSubscriberInterface
|
|||||||
public static function getSubscribedEvents(): array
|
public static function getSubscribedEvents(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
UserMenuEvent::EVENT => 'onUserMenuConfigure',
|
MenuEventType::USER=> 'onUserMenuConfigure',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user