Skip to content

Commit 483f029

Browse files
committed
Added a note about the advantages/drawbacks of listeners/subscribers
1 parent e56fed8 commit 483f029

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

cookbook/event_dispatcher/event_listener.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,3 +238,16 @@ done as follow::
238238
Two types of request are available in the :class:`Symfony\\Component\\HttpKernel\\HttpKernelInterface`
239239
interface: ``HttpKernelInterface::MASTER_REQUEST`` and
240240
``HttpKernelInterface::SUB_REQUEST``.
241+
242+
Events or Subscribers
243+
---------------------
244+
245+
Listeners and subscribers can be used in the same application indistinctly. The
246+
decision to use either of them is usually a matter of personal taste. However,
247+
there are some minor advantages for each of them:
248+
249+
* **Subscribers are easier to reuse** because the knowledge of the events is kept
250+
in the class rather than in the service definition. This is the reason why
251+
Symfony uses subscribers internally;
252+
* **Listeners are more flexible** because bundles can enable or disable each of
253+
them conditionally depending on some configuration value.

0 commit comments

Comments
 (0)