@@ -182,6 +182,63 @@ object with an ``EventDispatcher``. You can now create event listeners to
182
182
block transitions (i.e. depending on the data in the blog post). The following
183
183
events are dispatched:
184
184
185
+ * ``workflow.leave ``
186
+ * ``workflow.[workflow name].leave ``
187
+ * ``workflow.[workflow name].leave.[transition name] ``
188
+
189
+ * ``workflow.transition ``
190
+ * ``workflow.[workflow name].transition ``
191
+ * ``workflow.[workflow name].transition.[transition name] ``
192
+
193
+ * ``workflow.enter ``
194
+ * ``workflow.[workflow name].enter ``
195
+ * ``workflow.[workflow name].enter.[transition name] ``
196
+
197
+ * ``workflow.announce ``
198
+ * ``workflow.[workflow name].announce ``
199
+ * ``workflow.[workflow name].announce.[transition name] ``
200
+
201
+ Here is an example how to enable logging for every time a the "blog_publishing" workflow leaves a place::
202
+
203
+ use Psr\Log\LoggerInterface;
204
+ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
205
+ use Symfony\Component\Workflow\Event\Event;
206
+
207
+ class WorkflowLogger implements EventSubscriberInterface
208
+ {
209
+ public function __construct(LoggerInterface $logger)
210
+ {
211
+ $this->logger = $logger;
212
+ }
213
+
214
+ public function onLeave(Event $event)
215
+ {
216
+ $this->logger->alert(sprintf(
217
+ 'Blog post (id: "%s") preformed transaction "%s" form "%s" to "%s"',
218
+ $event->getSubject()->getId(),
219
+ $event->getTransition()->getName(),
220
+ implode(', ', array_keys($event->getMarking()->getPlaces())),
221
+ implode(', ', $event->getTransition()->getTos())
222
+ ));
223
+ }
224
+
225
+ public static function getSubscribedEvents()
226
+ {
227
+ return array(
228
+ 'workflow.blog_publishing.leave' => 'onLeave',
229
+ );
230
+ }
231
+ }
232
+
233
+ Guard events
234
+ ~~~~~~~~~~~~
235
+
236
+ There are a special kind of events called "Guard events". Their event listeners
237
+ are invoked every time a call to ``Workflow::can ``, ``Workflow::apply `` or
238
+ ``Workflow::getEnabledTransitions `` is executed. With the guard events you may
239
+ add custom logic to decide what transitions that are valid or not. Here is a list
240
+ of the guard event names.
241
+
185
242
* ``workflow.guard ``
186
243
* ``workflow.[workflow name].guard ``
187
244
* ``workflow.[workflow name].guard.[transition name] ``
@@ -213,14 +270,6 @@ See example to make sure no blog post without title is moved to "review"::
213
270
}
214
271
}
215
272
216
- With help from the ``EventDispatcher `` and the ``AuditTrailListener `` you
217
- could easily enable logging::
218
-
219
- use Symfony\Component\Workflow\EventListener\AuditTrailListener;
220
-
221
- $logger = new AnyPsr3Logger();
222
- $subscriber = new AuditTrailListener($logger);
223
- $dispatcher->addSubscriber($subscriber);
224
273
225
274
Event Methods
226
275
~~~~~~~~~~~~~
0 commit comments