第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

Symfony - 在捆綁包內(nèi)創(chuàng)建自己的配置(service.yaml)

Symfony - 在捆綁包內(nèi)創(chuàng)建自己的配置(service.yaml)

PHP
慕少森 2023-10-15 16:36:41
我花了很多時間嘗試某件事,但也許這是不可能的。抱歉我的語言不好。因此,我按照 Symfony Doc https://symfony.com/doc/current/bundles.html創(chuàng)建新的 Bundle,然后按照https://symfony.com/doc/current/bundles/extension.html創(chuàng)建 DI擴大。我的文件:AcmeHelloExtension.phpnamespace App\Acme\HelloBundle\DependencyInjection;use Symfony\Component\Config\FileLocator;use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;use Symfony\Component\DependencyInjection\Extension\Extension;use Symfony\Component\DependencyInjection\ContainerBuilder;class AcmeHelloExtension extends Extension{    public function load(array $configs, ContainerBuilder $container)    {        $loader = new XmlFileLoader(            $container,            new FileLocator(__DIR__.'/../Resources/config')        );        $loader->load('services.xml');    }}AcmeHelloBundle.phpnamespace App\Acme\HelloBundle;use Symfony\Component\HttpKernel\Bundle\Bundle;class AcmeHelloBundle extends Bundle{}我將其添加到 config/bundles.phpsrc/Acme/HelloBundle/Resources/config/services.yamlservices:    App\Acme\HelloBundle\AcmeHelloBundle:        tags: ['example-tags']該服務(wù)文件不會自動加載,我是否需要執(zhí)行后續(xù)步驟或者它應(yīng)該可以工作?當我使用 debug:container ....bundle... 檢查它時,選項標簽具有空值。當我將此代碼放入 config/services.yaml 時,它就可以工作。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經(jīng)驗 獲得超6個贊

基本問題是捆綁包的源代碼位于項目的 src 目錄下:


project

    src

        Ztest

            ZtestBundle.php

這反過來導(dǎo)致應(yīng)用程序的 config/services.yaml 文件自動裝配捆綁包的服務(wù):


# project\config\services

    App\:

        resource: '../src/'

        exclude:

            - '../src/DependencyInjection/'

            ...

            - '../src/Ztest' # Add this to fix the problem

排除捆綁包的源代碼解決了問題。應(yīng)用程序級別的自動接線會覆蓋在捆綁包級別完成的任何手動接線。


當然,一般來說,如果您確實決定需要一個捆綁包,那么它的源代碼應(yīng)該位于它自己的獨立目錄中:


project

    src

    src-ztest-bundle

為此,您還需要更新composer.json 的 psr-4 部分并運行“composer dump-autoload”。


請記住,在 Symfony 4+ 中,自定義捆綁包的唯一推薦用法是在多個 Symfony 應(yīng)用程序之間共享代碼。在這種情況下,捆綁包最終應(yīng)該位于它自己的存儲庫和作曲家包中。


但是,應(yīng)用程序內(nèi)部的自定義捆綁包仍然受支持,并且有時它們會很有用。


查看完整回答
反對 回復(fù) 2023-10-15
  • 1 回答
  • 0 關(guān)注
  • 129 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號