我有一个服务定义,如下所示:
app.logging.event_subscriber.my_subscriber:
class: AppBundle\Event\Subscriber\MySubscriber
arguments:
- '@?app.logging.optional_dependency'
tags:
- { name: kernel.event_subscriber }
如果缺少“app.logging.optional_dependency”服务,则不应定义我的服务“app.logging.event_subscriber.my_subscriber”,但我得到例外:
TypeError: Argument 1 passed to AppBundle\Event\Subscriber\MySubscriber::__construct() must be an instance of AppBundle\Logging\OptionalDependency, null given, called in /app/app/cache/test/appTestProjectContainer.php on line 936
答案 0 :(得分:2)
为构造函数null
AppBundle\Event\Subscriber\MySubscriber
public function __constructor (OptionalDependency $dependency = null)