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

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

如何防止在config / services.yaml中為捆綁包定義別名?

如何防止在config / services.yaml中為捆綁包定義別名?

PHP
躍然一笑 2021-05-06 14:31:34
我有一個捆綁包,例如,我希望能夠?qū)⑵渥⑷氲娇刂破髦?。我希望用戶要做的唯一一件事就是注冊捆綁軟件。然后可以隨意將服務(wù)注入到他們喜歡的任何地方:namespace App\Bundles;class MyService{    private $config;    public function __construct(array $options)    {        $this->config= $options;    }    public function hello()    {        echo "Hello world";    }}我試圖在config / services.yaml中定義這一行:App\Bundles\MyService: '@bundle_service'這似乎可行,但是我不希望用戶這樣做。這是我的配置類:class Configuration implements ConfigurationInterface{    public function getConfigTreeBuilder()    {        $treeBuilder = new TreeBuilder("my_bundle");        $treeBuilder->getRootNode()            ->children()                ->arrayNode('author')                    ->children()                        ->scalarNode("name")->end()                    ->end()                ->end()            ->end();        return $treeBuilder;    }}還有my_bundle配置文件,到目前為止,這只是一個測試:my_bundle:  author:    name: "Name"我的Bundle擴(kuò)展程序類:class MyBundleExtension extends Extension{    public function load(array $configs, ContainerBuilder $container)    {        $loader = new YamlFileLoader(            new FileLocator(__DIR__ .'/../Resources/config')        );        $loader->load('services.yaml');       $configuration = new Configuration();       $config = $this->processConfiguration($configuration, $configs);        $container->setDefinition('bundle_service', new Definition(MyService::class, [$config]));        $container->setAlias(MyService::class, 'bundle_service');    }}我的捆綁課程:class MyBundle extends Bundle{    public function getContainerExtension()    {        return new MyBundleExtension();    }}我想念的是什么。一切正常,除非我必須定義此行App\Bundles\MyService: '@bundle_service'中config/services.yaml,我不希望我的用戶這樣做。在MyBundleExtension中,我提供了正確的定義:        $container->setDefinition('bundle_service', new Definition(MyService::class, [$config]));        $container->setAlias(MyService::class, 'bundle_service');當(dāng)我遺漏config/services.yaml代碼時,出現(xiàn)此錯誤:Cannot autowire service "App\Bundles\MyService": argument "$options" of method "__construct()" 
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 158 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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