From d714a61a6d4e748eaed336019725ad6179f87ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Mon, 22 Dec 2025 15:27:41 +0100 Subject: [PATCH] Refactor service definitions in `menu.yaml` to use `_defaults` for autowiring and autoconfiguration, and update `SectionMenuBuilder` constructor with property promotion. --- .../Menu/SectionMenuBuilder.php | 29 ++++---------- .../ChillTaskBundle/config/services/menu.yaml | 39 ++++++++++--------- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/src/Bundle/ChillTaskBundle/Menu/SectionMenuBuilder.php b/src/Bundle/ChillTaskBundle/Menu/SectionMenuBuilder.php index 74933077b..8794fb5e3 100644 --- a/src/Bundle/ChillTaskBundle/Menu/SectionMenuBuilder.php +++ b/src/Bundle/ChillTaskBundle/Menu/SectionMenuBuilder.php @@ -19,23 +19,10 @@ use Symfony\Contracts\Translation\TranslatorInterface; class SectionMenuBuilder implements LocalMenuBuilderInterface { - /** - * @var AuthorizationCheckerInterface - */ - public $authorizationChecker; - - /** - * @var TranslatorInterface - */ - public $translator; - public function __construct( - AuthorizationCheckerInterface $authorizationChecker, - TranslatorInterface $translator, - ) { - $this->authorizationChecker = $authorizationChecker; - $this->translator = $translator; - } + private AuthorizationCheckerInterface $authorizationChecker, + private TranslatorInterface $translator, + ) {} public function buildMenu($menuId, MenuItem $menu, array $parameters): void { @@ -46,11 +33,11 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface $menu->addChild( $this->translator->trans('Tasks'), [ - 'route' => 'chill_task_singletask_list', [ - 'routeParameters' => [ - 'hide_form' => false, - ], - ], ] + 'route' => 'chill_task_singletask_list', + 'routeParameters' => [ + 'hide_form' => false, + ], + ] ) ->setExtras([ 'order' => 50, diff --git a/src/Bundle/ChillTaskBundle/config/services/menu.yaml b/src/Bundle/ChillTaskBundle/config/services/menu.yaml index 52322d553..d5141286d 100644 --- a/src/Bundle/ChillTaskBundle/config/services/menu.yaml +++ b/src/Bundle/ChillTaskBundle/config/services/menu.yaml @@ -1,22 +1,23 @@ services: - Chill\TaskBundle\Menu\UserMenuBuilder: - arguments: - $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' - $counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask' - $translator: '@Symfony\Contracts\Translation\TranslatorInterface' - $authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface' - tags: - - { name: "chill.menu_builder" } + _defaults: + autowire: true + autoconfigure: true - Chill\TaskBundle\Menu\MenuBuilder: - autowire: true - autoconfigure: true - tags: - - { name: "chill.menu_builder" } + Chill\TaskBundle\Menu\UserMenuBuilder: + arguments: + $tokenStorage: '@Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface' + $counter: '@Chill\TaskBundle\Templating\UI\CountNotificationTask' + $translator: '@Symfony\Contracts\Translation\TranslatorInterface' + $authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface' + tags: + - { name: "chill.menu_builder" } - Chill\TaskBundle\Menu\SectionMenuBuilder: - arguments: - $authorizationChecker: '@Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface' - $translator: '@Symfony\Contracts\Translation\TranslatorInterface' - tags: - - { name: "chill.menu_builder" } + Chill\TaskBundle\Menu\MenuBuilder: + autowire: true + autoconfigure: true + tags: + - { name: "chill.menu_builder" } + + Chill\TaskBundle\Menu\SectionMenuBuilder: + tags: + - { name: "chill.menu_builder" }