From c04e408d9d05b07a8bb7ece7c6d4f29224df1545 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 21 Oct 2022 11:08:31 +0200 Subject: [PATCH] DX: [calendar] simplify menu builder injection deps --- .../Menu/UserMenuBuilder.php | 38 ++++--------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php b/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php index db9276680..525039910 100644 --- a/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php +++ b/src/Bundle/ChillCalendarBundle/Menu/UserMenuBuilder.php @@ -12,51 +12,27 @@ declare(strict_types=1); namespace Chill\CalendarBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; -use Chill\TaskBundle\Templating\UI\CountNotificationTask; use Knp\Menu\MenuItem; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; -use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; class UserMenuBuilder implements LocalMenuBuilderInterface { - /** - * @var AuthorizationCheckerInterface - */ - public $authorizationChecker; + public TranslatorInterface $translator; - /** - * @var CountNotificationTask - */ - public $counter; - - /** - * @var TokenStorageInterface - */ - public $tokenStorage; - - /** - * @var TranslatorInterface - */ - public $translator; + private Security $security; public function __construct( - CountNotificationTask $counter, - TokenStorageInterface $tokenStorage, - TranslatorInterface $translator, - AuthorizationCheckerInterface $authorizationChecker + Security $security, + TranslatorInterface $translator ) { - $this->counter = $counter; - $this->tokenStorage = $tokenStorage; + $this->security = $security; $this->translator = $translator; - $this->authorizationChecker = $authorizationChecker; } public function buildMenu($menuId, MenuItem $menu, array $parameters) { - $user = $this->tokenStorage->getToken()->getUser(); - - if ($this->authorizationChecker->isGranted('ROLE_USER')) { + if ($this->security->isGranted('ROLE_USER')) { $menu->addChild('My calendar list', [ 'route' => 'chill_calendar_calendar_list_my', ])