From d6a6cc257235283c00b511dbf2ceb820fe11001c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Wed, 3 Apr 2024 17:14:02 +0200 Subject: [PATCH] Rename `chill.role` tag to `chill_main.provide_role` and optimize role provider The `chill.role` tag has been renamed to `chill_main.provide_role` to prevent any confusion and make the namespaces more consistent. During this process, the class RoleProvidersCompilerPass was deleted, simplifying the role provision process by injecting tagged services directly into the RoleProvider. The change is also reflected in multiple YAML service configurations and explained in the MIGRATION.md file. --- MIGRATION.md | 7 ++++ .../src/config/services/security.yaml | 1 - .../config/services/security.yaml | 1 - .../ChillDocStoreBundle/config/services.yaml | 2 - .../config/services/authorization.yaml | 4 +- .../ChillMainBundle/ChillMainBundle.php | 5 +-- .../RoleProvidersCompilerPass.php | 41 ------------------- .../Security/ProvideRoleInterface.php | 4 +- .../ChillMainBundle/Security/RoleProvider.php | 17 +++----- .../config/services/security.yaml | 2 + .../config/services/security.yaml | 2 - .../config/services/security.yaml | 2 - .../config/services/security.yaml | 1 - 13 files changed, 21 insertions(+), 68 deletions(-) create mode 100644 MIGRATION.md delete mode 100644 src/Bundle/ChillMainBundle/DependencyInjection/RoleProvidersCompilerPass.php diff --git a/MIGRATION.md b/MIGRATION.md new file mode 100644 index 000000000..deab7b449 --- /dev/null +++ b/MIGRATION.md @@ -0,0 +1,7 @@ + +# Switch to symfony 5.0 + +- the tag `chill.role` is now renamed to `chill_main.provide_role`. + + **Note**: It is not necessary to apply this tag on service definition: the tag is automatically applyied if the + service implements `\Chill\MainBundle\Security\ProvideRoleInterface`. diff --git a/src/Bundle/ChillAsideActivityBundle/src/config/services/security.yaml b/src/Bundle/ChillAsideActivityBundle/src/config/services/security.yaml index eb3327959..05bf9ebd9 100644 --- a/src/Bundle/ChillAsideActivityBundle/src/config/services/security.yaml +++ b/src/Bundle/ChillAsideActivityBundle/src/config/services/security.yaml @@ -4,4 +4,3 @@ services: autoconfigure: true tags: - { name: security.voter } - - { name: chill.role } \ No newline at end of file diff --git a/src/Bundle/ChillBudgetBundle/config/services/security.yaml b/src/Bundle/ChillBudgetBundle/config/services/security.yaml index c8f9e5cae..fec4e8f19 100644 --- a/src/Bundle/ChillBudgetBundle/config/services/security.yaml +++ b/src/Bundle/ChillBudgetBundle/config/services/security.yaml @@ -2,5 +2,4 @@ services: Chill\BudgetBundle\Security\Authorization\BudgetElementVoter: autowire: true tags: - - { name: chill.role } - { name: security.voter } diff --git a/src/Bundle/ChillDocStoreBundle/config/services.yaml b/src/Bundle/ChillDocStoreBundle/config/services.yaml index 55163abb3..667114679 100644 --- a/src/Bundle/ChillDocStoreBundle/config/services.yaml +++ b/src/Bundle/ChillDocStoreBundle/config/services.yaml @@ -11,8 +11,6 @@ services: Chill\DocStoreBundle\Security\Authorization\: resource: "./../Security/Authorization" - tags: - - { name: chill.role } Chill\DocStoreBundle\Workflow\: resource: './../Workflow/' diff --git a/src/Bundle/ChillEventBundle/config/services/authorization.yaml b/src/Bundle/ChillEventBundle/config/services/authorization.yaml index ca1eb789b..6f382b72e 100644 --- a/src/Bundle/ChillEventBundle/config/services/authorization.yaml +++ b/src/Bundle/ChillEventBundle/config/services/authorization.yaml @@ -6,9 +6,8 @@ services: - "@chill.main.security.authorization.helper" - "@logger" tags: - - { name: chill.role } - { name: security.voter } - + chill_event.event_participation: class: Chill\EventBundle\Security\Authorization\ParticipationVoter arguments: @@ -16,5 +15,4 @@ services: - "@chill.main.security.authorization.helper" - "@logger" tags: - - { name: chill.role } - { name: security.voter } diff --git a/src/Bundle/ChillMainBundle/ChillMainBundle.php b/src/Bundle/ChillMainBundle/ChillMainBundle.php index b7cf4e289..2305114f4 100644 --- a/src/Bundle/ChillMainBundle/ChillMainBundle.php +++ b/src/Bundle/ChillMainBundle/ChillMainBundle.php @@ -44,8 +44,6 @@ class ChillMainBundle extends Bundle $container->registerForAutoconfiguration(LocalMenuBuilderInterface::class) ->addTag('chill.menu_builder'); - $container->registerForAutoconfiguration(ProvideRoleInterface::class) - ->addTag('chill.role'); $container->registerForAutoconfiguration(CenterResolverInterface::class) ->addTag('chill_main.center_resolver'); $container->registerForAutoconfiguration(ScopeResolverInterface::class) @@ -64,11 +62,12 @@ class ChillMainBundle extends Bundle ->addTag('chill_main.cron_job'); $container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class) ->addTag('chill_main.entity_info_provider'); + $container->registerForAutoconfiguration(ProvideRoleInterface::class) + ->addTag('chill_main.provide_role'); $container->addCompilerPass(new SearchableServicesCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new ConfigConsistencyCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new TimelineCompilerClass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); - $container->addCompilerPass(new RoleProvidersCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new ExportsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new WidgetsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new NotificationCounterCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); diff --git a/src/Bundle/ChillMainBundle/DependencyInjection/RoleProvidersCompilerPass.php b/src/Bundle/ChillMainBundle/DependencyInjection/RoleProvidersCompilerPass.php deleted file mode 100644 index c4bbc846d..000000000 --- a/src/Bundle/ChillMainBundle/DependencyInjection/RoleProvidersCompilerPass.php +++ /dev/null @@ -1,41 +0,0 @@ -hasDefinition('chill.main.role_provider')) { - throw new \LogicException('service chill.main.role_provider is not defined. It is required by RoleProviderCompilerPass'); - } - - $definition = $container->getDefinition( - 'chill.main.role_provider' - ); - - $taggedServices = $container->findTaggedServiceIds( - 'chill.role' - ); - - foreach ($taggedServices as $id => $tagAttributes) { - $definition->addMethodCall( - 'addProvider', - [new Reference($id)] - ); - } - } -} diff --git a/src/Bundle/ChillMainBundle/Security/ProvideRoleInterface.php b/src/Bundle/ChillMainBundle/Security/ProvideRoleInterface.php index 204329f60..d34ea4f33 100644 --- a/src/Bundle/ChillMainBundle/Security/ProvideRoleInterface.php +++ b/src/Bundle/ChillMainBundle/Security/ProvideRoleInterface.php @@ -22,8 +22,10 @@ namespace Chill\MainBundle\Security; * my_role_declaration: * # ... * tags: - * - { name: chill.role } + * - { name: chill_main.provide_role } * + * + * This tag is also automatically added using dependency injection autoconfiguration. */ interface ProvideRoleInterface { diff --git a/src/Bundle/ChillMainBundle/Security/RoleProvider.php b/src/Bundle/ChillMainBundle/Security/RoleProvider.php index 95e4a666f..073c5bae8 100644 --- a/src/Bundle/ChillMainBundle/Security/RoleProvider.php +++ b/src/Bundle/ChillMainBundle/Security/RoleProvider.php @@ -13,10 +13,6 @@ namespace Chill\MainBundle\Security; class RoleProvider { - /** - * @var ProvideRoleInterface[] - */ - private array $providers = []; /** * an array where keys are the role, and value is the title @@ -26,14 +22,13 @@ class RoleProvider */ private ?array $rolesTitlesCache = null; - /** - * Add a role provider. - * - * @internal This function is called by the dependency injector: it inject provider - */ - public function addProvider(ProvideRoleInterface $provider) + public function __construct( + /** + * @var iterable + */ + private iterable $providers + ) { - $this->providers[] = $provider; } public function getRoles(): array diff --git a/src/Bundle/ChillMainBundle/config/services/security.yaml b/src/Bundle/ChillMainBundle/config/services/security.yaml index 38089becf..6c3f1afc6 100644 --- a/src/Bundle/ChillMainBundle/config/services/security.yaml +++ b/src/Bundle/ChillMainBundle/config/services/security.yaml @@ -44,6 +44,8 @@ services: chill.main.role_provider: class: Chill\MainBundle\Security\RoleProvider + arguments: + $providers: !tagged_iterator chill_main.provide_role Chill\MainBundle\Security\RoleProvider: '@chill.main.role_provider' chill.main.user_provider: diff --git a/src/Bundle/ChillPersonBundle/config/services/security.yaml b/src/Bundle/ChillPersonBundle/config/services/security.yaml index 4cdc16e74..f1b907bc6 100644 --- a/src/Bundle/ChillPersonBundle/config/services/security.yaml +++ b/src/Bundle/ChillPersonBundle/config/services/security.yaml @@ -11,14 +11,12 @@ services: class: Chill\PersonBundle\Security\Authorization\PersonVoter tags: - { name: security.voter } - - { name: chill.role } Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter: autowire: true autoconfigure: true tags: - { name: security.voter } - - { name: chill.role } Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter: autowire: true diff --git a/src/Bundle/ChillTaskBundle/config/services/security.yaml b/src/Bundle/ChillTaskBundle/config/services/security.yaml index c1d176637..b7c0c3aa2 100644 --- a/src/Bundle/ChillTaskBundle/config/services/security.yaml +++ b/src/Bundle/ChillTaskBundle/config/services/security.yaml @@ -3,5 +3,3 @@ services: class: Chill\TaskBundle\Security\Authorization\TaskVoter autowire: true autoconfigure: true - tags: - - { name: chill.role } diff --git a/src/Bundle/ChillThirdPartyBundle/config/services/security.yaml b/src/Bundle/ChillThirdPartyBundle/config/services/security.yaml index ccc47fcd2..8e3d9d4d4 100644 --- a/src/Bundle/ChillThirdPartyBundle/config/services/security.yaml +++ b/src/Bundle/ChillThirdPartyBundle/config/services/security.yaml @@ -4,4 +4,3 @@ services: $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' tags: - { name: security.voter } - - { name: chill.role }