Events
Last updated
Was this helpful?
Last updated
Was this helpful?
We use the to manage events at certain points when fetching data. This is useful to add adhoc functionality, such as logging.
The following events are available when accessing data.
data.request.start
StartEvent::NAME
Runs at the start of a request
getRequestId(), getUri(), getContext()
data.request.success
SuccessEvent::NAME
If a request is successful
getRequestId(), getUri(), getContext(), getException()
data.request.failure
FailureEvent::NAME
If a request is considered failed
getRequestId(), getUri(), getContext()
data.request.decode
DecodeEvent::NAME
After response has been decoded
getDecodedData(), getRequestId(), getUri(), getContext()
Event listeners are simple callbacks that run when a specific event is dispatched.
Use the addListener(string $eventName, callable $listener, int $priority = 0)
method to add a to an event. A simple example appears below:
An event subscriber is a class that can listen to multiple events. Since it's in a class it's easier to re-use code.
Add logging for the data request process.
Add timing profiling for the Symfony Stopwatch profiler (only recommended in development).
You can add an which can listen to multiple events via the addSubscriber(EventSubscriberInterface $subscriber)
method.