Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 572a0d9

Browse filesBrowse files
committed
Added docs about immutable dispatcher
1 parent de33db5 commit 572a0d9
Copy full SHA for 572a0d9

File tree

Expand file treeCollapse file tree

4 files changed

+52
-0
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+52
-0
lines changed
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.

‎components/event_dispatcher/index.rst

Copy file name to clipboardExpand all lines: components/event_dispatcher/index.rst
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ Event Dispatcher
77
introduction
88
generic_event
99
container_aware_dispatcher
10+
immutable_dispatcher

‎components/event_dispatcher/introduction.rst

Copy file name to clipboardExpand all lines: components/event_dispatcher/introduction.rst
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,15 @@ part of the listener's processing logic::
597597
}
598598
}
599599

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+
600609
.. _Observer: http://en.wikipedia.org/wiki/Observer_pattern
601610
.. _Closures: http://php.net/manual/en/functions.anonymous.php
602611
.. _PHP callable: http://www.php.net/manual/en/language.pseudo-types.php#language.types.callback

‎components/map.rst.inc

Copy file name to clipboardExpand all lines: components/map.rst.inc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
* :doc:`/components/event_dispatcher/introduction`
4646
* :doc:`/components/event_dispatcher/container_aware_dispatcher`
47+
* :doc:`/components/event_dispatcher/immutable_dispatcher`
4748
* :doc:`/components/event_dispatcher/generic_event`
4849

4950
* **Filesystem**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.