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.
This commit is contained in:
Julien Fastré 2024-04-03 17:14:02 +02:00
parent 0081146a78
commit d6a6cc2572
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
13 changed files with 21 additions and 68 deletions

7
MIGRATION.md Normal file
View File

@ -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`.

View File

@ -4,4 +4,3 @@ services:
autoconfigure: true autoconfigure: true
tags: tags:
- { name: security.voter } - { name: security.voter }
- { name: chill.role }

View File

@ -2,5 +2,4 @@ services:
Chill\BudgetBundle\Security\Authorization\BudgetElementVoter: Chill\BudgetBundle\Security\Authorization\BudgetElementVoter:
autowire: true autowire: true
tags: tags:
- { name: chill.role }
- { name: security.voter } - { name: security.voter }

View File

@ -11,8 +11,6 @@ services:
Chill\DocStoreBundle\Security\Authorization\: Chill\DocStoreBundle\Security\Authorization\:
resource: "./../Security/Authorization" resource: "./../Security/Authorization"
tags:
- { name: chill.role }
Chill\DocStoreBundle\Workflow\: Chill\DocStoreBundle\Workflow\:
resource: './../Workflow/' resource: './../Workflow/'

View File

@ -6,7 +6,6 @@ services:
- "@chill.main.security.authorization.helper" - "@chill.main.security.authorization.helper"
- "@logger" - "@logger"
tags: tags:
- { name: chill.role }
- { name: security.voter } - { name: security.voter }
chill_event.event_participation: chill_event.event_participation:
@ -16,5 +15,4 @@ services:
- "@chill.main.security.authorization.helper" - "@chill.main.security.authorization.helper"
- "@logger" - "@logger"
tags: tags:
- { name: chill.role }
- { name: security.voter } - { name: security.voter }

View File

@ -44,8 +44,6 @@ class ChillMainBundle extends Bundle
$container->registerForAutoconfiguration(LocalMenuBuilderInterface::class) $container->registerForAutoconfiguration(LocalMenuBuilderInterface::class)
->addTag('chill.menu_builder'); ->addTag('chill.menu_builder');
$container->registerForAutoconfiguration(ProvideRoleInterface::class)
->addTag('chill.role');
$container->registerForAutoconfiguration(CenterResolverInterface::class) $container->registerForAutoconfiguration(CenterResolverInterface::class)
->addTag('chill_main.center_resolver'); ->addTag('chill_main.center_resolver');
$container->registerForAutoconfiguration(ScopeResolverInterface::class) $container->registerForAutoconfiguration(ScopeResolverInterface::class)
@ -64,11 +62,12 @@ class ChillMainBundle extends Bundle
->addTag('chill_main.cron_job'); ->addTag('chill_main.cron_job');
$container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class) $container->registerForAutoconfiguration(ViewEntityInfoProviderInterface::class)
->addTag('chill_main.entity_info_provider'); ->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 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 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 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 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 WidgetsCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);
$container->addCompilerPass(new NotificationCounterCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0); $container->addCompilerPass(new NotificationCounterCompilerPass(), \Symfony\Component\DependencyInjection\Compiler\PassConfig::TYPE_BEFORE_OPTIMIZATION, 0);

View File

@ -1,41 +0,0 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class RoleProvidersCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->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)]
);
}
}
}

View File

@ -22,8 +22,10 @@ namespace Chill\MainBundle\Security;
* my_role_declaration: * my_role_declaration:
* # ... * # ...
* tags: * tags:
* - { name: chill.role } * - { name: chill_main.provide_role }
* </pre> * </pre>
*
* This tag is also automatically added using dependency injection autoconfiguration.
*/ */
interface ProvideRoleInterface interface ProvideRoleInterface
{ {

View File

@ -13,10 +13,6 @@ namespace Chill\MainBundle\Security;
class RoleProvider class RoleProvider
{ {
/**
* @var ProvideRoleInterface[]
*/
private array $providers = [];
/** /**
* an array where keys are the role, and value is the title * an array where keys are the role, and value is the title
@ -26,14 +22,13 @@ class RoleProvider
*/ */
private ?array $rolesTitlesCache = null; private ?array $rolesTitlesCache = null;
/** public function __construct(
* Add a role provider. /**
* * @var iterable<ProvideRoleInterface>
* @internal This function is called by the dependency injector: it inject provider */
*/ private iterable $providers
public function addProvider(ProvideRoleInterface $provider) )
{ {
$this->providers[] = $provider;
} }
public function getRoles(): array public function getRoles(): array

View File

@ -44,6 +44,8 @@ services:
chill.main.role_provider: chill.main.role_provider:
class: Chill\MainBundle\Security\RoleProvider class: Chill\MainBundle\Security\RoleProvider
arguments:
$providers: !tagged_iterator chill_main.provide_role
Chill\MainBundle\Security\RoleProvider: '@chill.main.role_provider' Chill\MainBundle\Security\RoleProvider: '@chill.main.role_provider'
chill.main.user_provider: chill.main.user_provider:

View File

@ -11,14 +11,12 @@ services:
class: Chill\PersonBundle\Security\Authorization\PersonVoter class: Chill\PersonBundle\Security\Authorization\PersonVoter
tags: tags:
- { name: security.voter } - { name: security.voter }
- { name: chill.role }
Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter: Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter:
autowire: true autowire: true
autoconfigure: true autoconfigure: true
tags: tags:
- { name: security.voter } - { name: security.voter }
- { name: chill.role }
Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter: Chill\PersonBundle\Security\Authorization\AccompanyingPeriodCommentVoter:
autowire: true autowire: true

View File

@ -3,5 +3,3 @@ services:
class: Chill\TaskBundle\Security\Authorization\TaskVoter class: Chill\TaskBundle\Security\Authorization\TaskVoter
autowire: true autowire: true
autoconfigure: true autoconfigure: true
tags:
- { name: chill.role }

View File

@ -4,4 +4,3 @@ services:
$authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper' $authorizationHelper: '@Chill\MainBundle\Security\Authorization\AuthorizationHelper'
tags: tags:
- { name: security.voter } - { name: security.voter }
- { name: chill.role }