@@ -120,7 +120,9 @@ Creating the Listener Class
120
120
121
121
In the previous example, a service ``my.listener `` was configured as a Doctrine
122
122
listener on the event ``postPersist ``. That class behind that service must have
123
- a ``postPersist `` method, which will be called when the event is thrown::
123
+ a ``postPersist `` method, which will be called when the event is thrown.
124
+
125
+ .. code-block::php
124
126
125
127
// src/Acme/SearchBundle/EventListener/SearchIndexer.php
126
128
namespace Acme\SearchBundle\EventListener;
@@ -158,6 +160,7 @@ Creating the Subscriber Class
158
160
A doctrine event subscriber must implement the ``Doctrine\Common\EventSubscriber ``
159
161
interface and an event method for each event it subscribes to.
160
162
163
+ .. code-block::php
161
164
162
165
// src/Acme/SearchBundle/EventListener/SearchIndexerSubscriber.php
163
166
namespace Acme\SearchBundle\EventListener;
@@ -175,14 +178,17 @@ interface and an event method for each event it subscribes to.
175
178
'postUpdate',
176
179
);
177
180
}
181
+
178
182
public function postUpdate(LifecycleEventArgs $args)
179
183
{
180
184
$this->index($args);
181
185
}
186
+
182
187
public function postPersist(LifecycleEventArgs $args)
183
188
{
184
189
$this->index($args);
185
190
}
191
+
186
192
public function index(LifecycleEventArgs $args)
187
193
{
188
194
$entity = $args->getEntity();
@@ -195,7 +201,7 @@ interface and an event method for each event it subscribes to.
195
201
}
196
202
}
197
203
198
- .. hint ::
204
+ .. tip ::
199
205
200
206
Doctrine event subscribers can not return a flexible array of methods to
201
207
call for the events like the :ref: `Symfony event subscriber <event_dispatcher-using-event-subscribers >`
0 commit comments