File tree Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Expand file tree Collapse file tree 4 files changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ .. index ::
2
+ single: Event Dispatcher; Immutable
3
+
4
+ The Immutable Event Dispatcher
5
+ ==============================
6
+
7
+ .. versionadded :: 2.1
8
+ This feature was added in Symfony 2.1.
9
+
10
+ The :class: `Symfony\\ Component\\ EventDispatcher\\ ImmutableEventDispatcher ` is
11
+ a locked or frozen event dispatcher. The dispatcher cannot register new
12
+ listeners or subscribers.
13
+
14
+ The ``ImmutableEventDispatcher `` takes another event dispatcher with all the
15
+ listeners and subscribers. The immutable dispatcher is just a proxy of this
16
+ original dispatcher.
17
+
18
+ To use it, first create a normal dispatcher (``EventDispatcher `` or
19
+ ``ContainerAwareEventDispatcher ``) and register some listeners or
20
+ subscribers::
21
+
22
+ use Symfony\Component\EventDispatcher\EventDispatcher;
23
+
24
+ $dispatcher = new EventDispatcher();
25
+ $dispatcher->addListener('foo.action', function ($event) {
26
+ // ...
27
+ });
28
+
29
+ // ...
30
+
31
+ Now, inject that into an ``ImmutableEventDispatcher ``::
32
+
33
+ use Symfony\Component\EventDispatcher\ImmutableEventDispatcher;
34
+ // ...
35
+
36
+ $immutableDispatcher = new ImmutableEventDispatcher($dispatcher);
37
+
38
+ You'll need to use this new dispatcher in your project.
39
+
40
+ If you are trying to execute one of the methods which modifies the dispatcher
41
+ (e.g. ``addListener ``), a ``BadMethodCallException `` is thrown.
Original file line number Diff line number Diff line change @@ -7,3 +7,4 @@ Event Dispatcher
7
7
introduction
8
8
generic_event
9
9
container_aware_dispatcher
10
+ immutable_dispatcher
Original file line number Diff line number Diff line change @@ -597,6 +597,15 @@ part of the listener's processing logic::
597
597
}
598
598
}
599
599
600
+ Other Dispatchers
601
+ -----------------
602
+
603
+ Besides the commonly used ``EventDispatcher ``, the component comes with 2
604
+ other dispatchers:
605
+
606
+ * :doc: `/components/event_dispatcher/container_aware_dispatcher `
607
+ * :doc: `/components/event_dispatcher/immutable_dispatcher `
608
+
600
609
.. _Observer : http://en.wikipedia.org/wiki/Observer_pattern
601
610
.. _Closures : http://php.net/manual/en/functions.anonymous.php
602
611
.. _PHP callable : http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback
Original file line number Diff line number Diff line change 44
44
45
45
* :doc:` /components/event_dispatcher/introduction`
46
46
* :doc:` /components/event_dispatcher/container_aware_dispatcher`
47
+ * :doc:` /components/event_dispatcher/immutable_dispatcher`
47
48
* :doc:` /components/event_dispatcher/generic_event`
48
49
49
50
* ** Filesystem**
You can’t perform that action at this time.
0 commit comments