我正在使用JMS DI注入带注释的服务:
use JMS\DiExtraBundle\Annotation as DI;
/**
* @DI\Service("foo.bar.service")
*/
class myClass
{
/**
* @DI\Inject("debug.stopwatch")
* @var $stopWatch \Symfony\Component\Stopwatch\Stopwatch
*/
public $stopWatch;
/**
* @DI\Inject("serializer")
* @var $serializer \JMS\Serializer\Serializer
*/
public $serializer;
public function toto()
{
if (isset($this->stopwatch)) {
$this->stopWatch->start("init");
}
}
}
但StopWatch仅在Dev Env中可用,所以在prod中运行时:
The service "foo.bar.service" has a dependency on a non-existent service "debug.stopwatch".' in...
我的问题:如何在课堂上正确注入秒表服务?