Skip to content

Commit 31f3145

Browse files
committed
typos detected by stof and add parameters section via xml and php
1 parent a42782f commit 31f3145

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

cookbook/event_dispatcher/before_after_filters.rst

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ or just after our controller actions acting as filters or hooks.
99

1010
In Symfony1, this was achieved with the preExecute and postExecute methods, most major frameworks have similar
1111
methods but there is no such thing in Symfony2. Good news is that there is a much better way to interfere our
12-
Request -> Response process with the EventListener component.
12+
Request -> Response process with the EventDispatcher component.
1313

1414
Token validation example
1515
========================
@@ -22,8 +22,8 @@ And if it is restricted, we need to validate the provided token.
2222

2323
.. note::
2424

25-
Please note that for simplicity in the recipe, tokens will be defined in config
26-
and neither database setup nor authentication provider via Security component will be used
25+
Please note that for simplicity in the recipe, tokens will be defined in config
26+
and neither database setup nor authentication provider via Security component will be used
2727

2828
Creating a before filter with a controller.request event
2929
========================================================
@@ -43,6 +43,23 @@ We can add basic tokens configuration using config.yml and parameters key
4343
client1: pass1
4444
client2: pass2
4545
46+
.. code-block:: xml
47+
48+
<!-- app/config/config.xml -->
49+
<parameters>
50+
<parameter key="tokens" type="collection">
51+
<parameter key="client1">pass1</parameter>
52+
<parameter key="client2">pass2</parameter>
53+
</parameter>
54+
</parameters>
55+
56+
.. code-block:: php
57+
58+
// app/config/config.php
59+
$container->setParameter('tokens', array(
60+
'client1' => 'pass1',
61+
'client2' => 'pass2'
62+
));
4663
4764
Tag controllers to be checked
4865
-----------------------------
@@ -58,12 +75,12 @@ A clean and easy way is to create an empty interface and make the controllers im
5875
5976
interface TokenAuthenticatedController
6077
{
61-
// Nothing here
78+
// Nothing here
6279
}
6380
6481
class FooController implements TokenAuthenticatedController
6582
{
66-
// Your actions that need authentication
83+
// Your actions that need authentication
6784
}
6885
6986
Creating an Event Listener
@@ -92,7 +109,9 @@ Creating an Event Listener
92109
* $controller passed can be either a class or a Closure. This is not usual in Symfony2 but it may happen.
93110
* If it is a class, it comes in array format
94111
*/
95-
if (!is_array($controller)) return;
112+
if (!is_array($controller)) {
113+
return;
114+
}
96115
97116
if($controller[0] instanceof TokenAuthenticatedController) {
98117
$token = $event->getRequest()->get('token');
@@ -103,8 +122,8 @@ Creating an Event Listener
103122
}
104123
}
105124
106-
Tagging the EventListener
107-
-------------------------
125+
Registering the listener
126+
------------------------
108127

109128
.. configuration-block::
110129

0 commit comments

Comments
 (0)