亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Symfony 服務,tagged_locator 適用于 yaml 中的配置,但不適用于 php

Symfony 服務,tagged_locator 適用于 yaml 中的配置,但不適用于 php

PHP
慕田峪4524236 2023-10-21 17:22:21
我在服務配置中使用 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/',            ]        );
查看完整描述

1 回答

?
LEATH

TA貢獻1936條經驗 獲得超7個贊

配置器是不可變的:您需要存儲和使用調用defaults()和instanceof()的返回值:


    $services = $services->defaults()

        ->autowire()

        ->autoconfigure();


    $services = $services->instanceof(CriterionInterface::class)

        ->tag('app.post');


    $services->load('App\\', __DIR__.'/../src/')

        ->exclude(

            [

                __DIR__.'/../src/DependencyInjection/',

                __DIR__.'/../src/Entity/',

                __DIR__.'/../src/Kernel.php',

                __DIR__.'/../src/Tests/',

            ]

        );

Instanceof 條件必須在基于路徑的服務發現之前配置(第一次調用 load())


查看完整回答
反對 回復 2023-10-21
  • 1 回答
  • 0 關注
  • 112 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號