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
This commit is contained in:
Julie Lenaerts 2024-06-19 10:16:39 +02:00
parent 830dace1ba
commit 062afd6695
2 changed files with 7 additions and 5 deletions

View File

@ -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');

View File

@ -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 }