From e0828b1f0fa9d9c255a6a1189492e33d7c2ca31d Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Wed, 19 Jun 2024 10:16:39 +0200 Subject: [PATCH] Use service tags to inject all voters into StoredObjectVoter.php Instead of manually injecting services into StoredObjectVoter\ config is added to automatically tag each service that implements\ StoredObjectVoterInterface.php --- .../DependencyInjection/ChillDocStoreExtension.php | 3 +++ .../ChillDocStoreBundle/config/services/security.yaml | 9 ++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php b/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php index a0fcc2d5d..9f277e716 100644 --- a/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php +++ b/src/Bundle/ChillDocStoreBundle/DependencyInjection/ChillDocStoreExtension.php @@ -14,6 +14,7 @@ namespace Chill\DocStoreBundle\DependencyInjection; use Chill\DocStoreBundle\Controller\StoredObjectApiController; use Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; +use ChillDocStoreBundle\Security\Authorization\StoredObjectVoterInterface; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; @@ -35,6 +36,8 @@ class ChillDocStoreExtension extends Extension implements PrependExtensionInterf $container->setParameter('chill_doc_store', $config); + $container->registerForAutoconfiguration(StoredObjectVoterInterface::class)->addTag('stored_object_voter'); + $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config')); $loader->load('services.yaml'); $loader->load('services/controller.yaml'); diff --git a/src/Bundle/ChillDocStoreBundle/config/services/security.yaml b/src/Bundle/ChillDocStoreBundle/config/services/security.yaml index 922d29cba..c57eb63c5 100644 --- a/src/Bundle/ChillDocStoreBundle/config/services/security.yaml +++ b/src/Bundle/ChillDocStoreBundle/config/services/security.yaml @@ -4,11 +4,10 @@ services: autoconfigure: true Chill\DocStoreBundle\Security\Authorization\StoredObjectVoter: arguments: - $storedObjectVoters: - # context specific voters - - '@accompanying_course_document_voter' + $storedObjectVoters: !tagged_iterator stored_object_voter tags: - { name: security.voter } - accompanying_course_document_voter: - class: Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter + Chill\DocStoreBundle\Security\Authorization\AccompanyingCourseDocumentVoter: + tags: + - { name: security.voter }