我在服務配置中使用 tagged_locator 一切都可以使用 yaml 配置。但是當我在php中進行配置時,它不再起作用了。我的服務的參數沒有填寫(0個providedServices)配置Yamlservices: # default configuration for services in *this* file _defaults: autowire: true # Automatically injects dependencies in your services. autoconfigure: true # Automatically registers your services as commands, event subscribers, etc. # makes classes in src/ available to be used as services # this creates a service per class whose id is the fully-qualified class name App\: resource: '../src/' exclude: - '../src/DependencyInjection/' - '../src/Entity/' - '../src/Kernel.php' - '../src/Tests/' # controllers are imported separately to make sure services can be injected # as action arguments even if you don't extend any base controller class App\Controller\: resource: '../src/Controller/' tags: ['controller.service_arguments'] # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones # Will tag automatically all service that implement the VoterInterface created _instanceof: App\Voter\CriterionInterface: tags: - 'app.post.voter.criterion' App\Voter\PostVoter: arguments: - !tagged_locator 'app.post.voter.criterion'配置PHPreturn static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); $services->defaults() ->autowire() ->autoconfigure(); $services->load('App\\', __DIR__.'/../src/') ->exclude( [ __DIR__.'/../src/DependencyInjection/', __DIR__.'/../src/Entity/', __DIR__.'/../src/Kernel.php', __DIR__.'/../src/Tests/', ] );
Symfony 服務,tagged_locator 適用于 yaml 中的配置,但不適用于 php
慕田峪4524236
2023-10-21 17:22:21