我在服务配置中使用 tagged_locator 一切都可以使用 yaml 配置。但是当我在php中进行配置时,它不再起作用了。我的服务的参数没有填写(0个providedServices)
配置Yaml
services:
# 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'
配置PHP
return 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/',
]
);
LEATH