Skip to content

GetResponse*Events stop after a response was set #4532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions components/http_kernel/introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ return a ``Response`` directly, or to add information to the ``Request``
(e.g. setting the locale or setting some other information on the ``Request``
attributes).

.. note::

When setting a response for the ``kernel.request`` event, the propagation
is stopped. This means listeners with lower priority won't be executed.

.. sidebar:: ``kernel.request`` in the Symfony Framework

The most important listener to ``kernel.request`` in the Symfony Framework
Expand Down Expand Up @@ -391,6 +396,11 @@ At this stage, if no listener sets a response on the event, then an exception
is thrown: either the controller *or* one of the view listeners must always
return a ``Response``.

.. note::

When setting a response for the ``kernel.view`` event, the propagation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 times the same note?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's for different events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes you're right. Should be kernel.request above.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's fixed now 😄

is stopped. This means listeners with lower priority won't be executed.

.. sidebar:: ``kernel.view`` in the Symfony Framework

There is no default listener inside the Symfony Framework for the ``kernel.view``
Expand Down Expand Up @@ -522,6 +532,11 @@ comes with an :class:`Symfony\\Component\\HttpKernel\\EventListener\\ExceptionLi
which if you choose to use, will do this and more by default (see the sidebar
below for more details).

.. note::

When setting a response for the ``kernel.exception`` event, the propagation
is stopped. This means listeners with lower priority won't be executed.

.. sidebar:: ``kernel.exception`` in the Symfony Framework

There are two main listeners to ``kernel.exception`` when using the
Expand Down
6 changes: 6 additions & 0 deletions cookbook/service_container/event_listener.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ event is just one of the core kernel events::
the ``kernel.exception`` event, it is :class:`Symfony\\Component\\HttpKernel\\Event\\GetResponseForExceptionEvent`.
To see what type of object each event listener receives, see :class:`Symfony\\Component\\HttpKernel\\KernelEvents`.

.. note::

When setting a response for the ``kernel.request``, ``kernel.view`` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt this "or" instead oft "and"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact if you set it for kernel.request kernel.view won't even be triggered, and kernel.exception is exclusive with kernel.view (and is triggered after kernel.request) so I thought and was better.

Also, I'm refering to the set of the 3 events.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's due to how you would write this in german by I agree with @timglabisch here that "or" sounds more correct.

What do you think about rewording this a bit to make it more clear (sadly, I don't have a good idea right now).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, in german "or" would be more natural.

`kernel.request``, ``kernel.view`` and

you dont have to set kernel.request AND kernel.view AND ...., it's more like this is true for kernel.request || kernel.view | | ... :)

but "and" sounds ok for me, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should indeed be OR. The event has to be either kernel.request, kernel.view or kernel.exception. It can't be kernel.request AND kernel.view AND kernel.exception at the same time, it's one of them. (but well, this is a very high technical view on this topic, I think both are ok to use)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree - should be OR - I've got it changed at sha: 5842f5c

Thanks!

``kernel.exception`` events, the propagation is stopped, so the lower
priority listeners on that event don't get called.

Now that the class is created, you just need to register it as a service and
notify Symfony that it is a "listener" on the ``kernel.exception`` event by
using a special "tag":
Expand Down