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 a6b17a0

Browse filesBrowse files
Bruno Ferme GasparinBruno Ferme Gasparin
authored andcommitted
Added KernelEvent::isMasterRequest method reference
1 parent 8e8b8a0 commit a6b17a0
Copy full SHA for a6b17a0

File tree

Expand file treeCollapse file tree

3 files changed

+22
-11
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+22
-11
lines changed

‎book/internals.rst

Copy file name to clipboardExpand all lines: book/internals.rst
+10-3Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ processing must only occur on the master request).
208208
Events
209209
~~~~~~
210210

211+
.. versionadded:: 2.4
212+
The ``isMasterRequest()`` method was introduced in Symfony 2.4.
213+
Prior, the ``getRequestType()`` method must be used.
214+
211215
Each event thrown by the Kernel is a subclass of
212216
:class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`. This means that
213217
each event has access to the same basic information:
@@ -216,22 +220,25 @@ each event has access to the same basic information:
216220
- returns the *type* of the request (``HttpKernelInterface::MASTER_REQUEST``
217221
or ``HttpKernelInterface::SUB_REQUEST``);
218222

223+
* :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::isMasterRequest`
224+
- checks if it is a master request;
225+
219226
* :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getKernel`
220227
- returns the Kernel handling the request;
221228

222229
* :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequest`
223230
- returns the current ``Request`` being handled.
224231

225-
``getRequestType()``
232+
``IsMasterRequest()``
226233
....................
227234

228-
The ``getRequestType()`` method allows listeners to know the type of the
235+
The ``isMasterRequest()`` method allows listeners to check the type of the
229236
request. For instance, if a listener must only be active for master requests,
230237
add the following code at the beginning of your listener method::
231238

232239
use Symfony\Component\HttpKernel\HttpKernelInterface;
233240

234-
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
241+
if (!$event->isMasterRequest()) {
235242
// return immediately
236243
return;
237244
}

‎components/http_kernel/introduction.rst

Copy file name to clipboardExpand all lines: components/http_kernel/introduction.rst
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,12 +665,16 @@ argument as follows::
665665
$response = $kernel->handle($request, HttpKernelInterface::SUB_REQUEST);
666666
// do something with this response
667667

668+
.. versionadded:: 2.4
669+
The ``isMasterRequest()`` method was introduced in Symfony 2.4.
670+
Prior, the ``getRequestType()`` method must be used.
671+
668672
This creates another full request-response cycle where this new ``Request`` is
669673
transformed into a ``Response``. The only difference internally is that some
670674
listeners (e.g. security) may only act upon the master request. Each listener
671675
is passed some sub-class of :class:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent`,
672-
whose :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::getRequestType`
673-
can be used to figure out if the current request is a "master" or "sub" request.
676+
whose :method:`Symfony\\Component\\HttpKernel\\Event\\KernelEvent::isMasterRequest`
677+
can be used to check if the current request is a "master" or "sub" request.
674678

675679
For example, a listener that only needs to act on the master request may
676680
look like this::
@@ -680,7 +684,7 @@ look like this::
680684

681685
public function onKernelRequest(GetResponseEvent $event)
682686
{
683-
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
687+
if (!$event->isMasterRequest()) {
684688
return;
685689
}
686690

‎cookbook/service_container/event_listener.rst

Copy file name to clipboardExpand all lines: cookbook/service_container/event_listener.rst
+5-5Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ using a special "tag":
100100
Request events, checking types
101101
------------------------------
102102

103+
.. versionadded:: 2.4
104+
The ``isMasterRequest()`` method was introduced in Symfony 2.4.
105+
Prior, the ``getRequestType()`` method must be used.
106+
103107
A single page can make several requests (one master request, and then multiple
104108
sub-requests), which is why when working with the ``KernelEvents::REQUEST``
105109
event, you might need to check the type of the request. This can be easily
@@ -115,7 +119,7 @@ done as follow::
115119
{
116120
public function onKernelRequest(GetResponseEvent $event)
117121
{
118-
if (false === $event->isMasterRequest()) {
122+
if (!$event->isMasterRequest()) {
119123
// don't do anything if it's not the master request
120124
return;
121125
}
@@ -124,10 +128,6 @@ done as follow::
124128
}
125129
}
126130

127-
.. versionadded:: 2.4
128-
The ``isMasterRequest()`` method was introduced in Symfony 2.4.
129-
Prior, the ``getRequestType()`` method must be used.
130-
131131
.. tip::
132132

133133
Two types of request are available in the :class:`Symfony\\Component\\HttpKernel\\HttpKernelInterface`

0 commit comments

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