The Immutable Event Dispatcher

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

ImmutableEventDispatcher は、ロックまたは凍結されたイベント ディスパッチャです。ディスパッチャーは、新しいリスナーまたはサブスクライバーを登録できません。

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

ImmutableEventDispatcher は、すべてのリスナーとサブスクライバーを持つ別のイベント ディスパッチャーを取ります。不変のディスパッチャは、この元のディスパッチャの単なるプロキシです。

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

これを使用するには、まず通常の EventDispatcher ディスパッチャーを作成し、いくつかのリスナーまたはサブスクライバーを登録します。
1
2
3
4
5
6
7
8
use Symfony\Component\EventDispatcher\EventDispatcher;

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

// ...

Now, inject that into an ImmutableEventDispatcher:

次に、それを ImmutableEventDispatcher に挿入します。
1
2
3
4
use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
// ...

$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.

ディスパッチャーを変更するメソッド (addListener() など) のいずれかを実行しようとすると、BadMethodCallException がスローされます。