概述 快速入门 教程 手册 最佳实践 组件 参考 贡献

发布于 2015-08-27 16:48:15 | 190 次阅读 | 评论: 0 | 来源: 网络整理

The ImmutableEventDispatcher is a locked or frozen event dispatcher. The dispatcher cannot register new listeners or subscribers.

The ImmutableEventDispatcher takes another event dispatcher with all the listeners and subscribers. The immutable dispatcher is just a proxy of this original dispatcher.

To use it, first create a normal dispatcher (EventDispatcher or ContainerAwareEventDispatcher) and register some listeners or subscribers:

use SymfonyComponentEventDispatcherEventDispatcher;

$dispatcher = new EventDispatcher();
$dispatcher->addListener('foo.action', function ($event) {
    // ...
});

// ...

Now, inject that into an ImmutableEventDispatcher:

use SymfonyComponentEventDispatcherImmutableEventDispatcher;
// ...

$immutableDispatcher = new ImmutableEventDispatcher($dispatcher);

You’ll need to use this new dispatcher in your project.

If you are trying to execute one of the methods which modifies the dispatcher (e.g. addListener), a BadMethodCallException is thrown.

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务