我正在尝试在Symfony 2中构建我的第一个Compiler Pass.现在,我只是想在SampleBundle中从FrameWorkBundle获取核心event_dispatcher服务,但是我收到了这个错误:
error InvalidArgumentException: The service definition "event_dispatcher" does not exist.
Run Code Online (Sandbox Code Playgroud)
这是我的编译器的代码:
<?php
namespace Me\SampleBunlde\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
class RegisterListenersPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('event_dispatcher');
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我有点惊讶,因为我一步一步地遵循一本专业的Symfony书,向我保证我会找到这个服务.
我已经做了一些关于这方面的研究,我发现只有debug.event_dispatcher服务是可用的.然后我检查了别名,发现有一个名为'event_dispatcher'的私有Alias指向debug.event_dispatcher.所以我真的很困惑.而且我想知道:
谢谢您的帮助 !
symfony ×1