unlikelysource.com

$event->trigger(x, y, z, callback) -- when would you define callback?


$event->trigger(x, y, z, callback) -- when would you define callback?
A: If you want "trigger" to behave as "triggerUntil()".  Keeps triggering until callback returns TRUE.

$event->trigger(x, y, z, callback) -- when would you define callback?
A: [MWOP] The callback used with trigger() is used to test the return value of
individual listeners; returning a boolean true value from this callback
will halt execution of the event loop. The rationale can be seen in the
MVC, where if a Response is detected as being returned from a listener,
we halt execution of the event loop and return immediately. As an
example:

$results = $events->trigger('dispatch', $this, $mvcEvent, function ($result) {
if ($result instanceof Response) {
return true;
}
});
if ($results->stopped()) {
return $results->last(); // if we were halted due to the
// callback, return the last result now
}


BACK

© 2018 unlikelysource.com | all rights reserved