当我在Yaml Service Config中配置Symfony 3.4时不设置参数

时间:2018-11-22 09:14:16

标签: symfony service yaml symfony-3.4

我使用Symfony 3.4,并尝试将Silex应用程序迁移到它。所以我不能使用Symfony的自动装配。

我的service.yml看起来像

{
"GCM": "{ \"notification\": { \"body\": \"hello....\", \"title\": \"title123\" } }"
}

已编译的cach类如下:

services:
# default configuration for services in *this* file
 _defaults:
 # automatically injects dependencies in your services
  autowire: false
  # automatically registers your services as commands, event subscribers, etc.
  autoconfigure: false
  # this means you cannot fetch services directly from the container via $container->get()
  # if you need to do this, you can override this setting on individual services
  public: false

  audit.persister.base:
   class: MyBundle\Security\Audit\Persister\ChainedEntityTrailPersister
   calls:
    - method: 'addPersister'
      argument:
       - '@audit.persister_elasticsearch'

我得到了一个错误:

$this->services['audit.persister.base'] = $instance = new \MyBundle\Security\Audit\Persister\ChainedEntityTrailPersister();

$instance->addPersister();

错误是正确的。因为缓存的类创建者不提供我在config中设置的参数。

有人知道为什么该参数不会在生成的缓存中设置吗?

2 个答案:

答案 0 :(得分:1)

在Symfony中,习惯于在一行中编写呼叫:

SolrConfig.xml

此外,您可以将PHPStorm与Symfony plugin配合使用以实现自动完成。多亏了这一点,您从错别字中解脱了,它基本上为您写了:)

答案 1 :(得分:0)

documentation中,您可能会拥有:

  audit.persister.base:
     class: MyBundle\Security\Audit\Persister\ChainedEntityTrailPersister
     calls:
         - method: 'addPersister'
          arguments:
               - '@audit.persister_elasticsearch'

arguments,结尾为s