Skip to content

Instantly share code, notes, and snippets.

@nclundsten
Created June 15, 2013 22:30
Show Gist options
  • Save nclundsten/5789823 to your computer and use it in GitHub Desktop.
Save nclundsten/5789823 to your computer and use it in GitHub Desktop.
protected function triggerListeners($event, EventInterface $e, $callback = null)
{
$responses = new ResponseCollection;
$listeners = $this->getListeners($event);
// Add shared/wildcard listeners to the list of listeners,
// but don't modify the listeners object
$sharedListeners = $this->getSharedListeners($event);
$sharedWildcardListeners = $this->getSharedListeners('*');
$wildcardListeners = $this->getListeners('*');
if (count($sharedListeners) || count($sharedWildcardListeners) || count($wildcardListeners)) {
$listeners = clone $listeners;
// Shared listeners on this specific event
$this->insertListeners($listeners, $sharedListeners);
// Shared wildcard listeners
$this->insertListeners($listeners, $sharedWildcardListeners);
// Add wildcard listeners
$this->insertListeners($listeners, $wildcardListeners);
}
foreach ($listeners as $listener) {
$listenerCallback = $listener->getCallback();
////////////////////////////////////////////////////////////
if ($event = 'pickAddressesAction.validate') {
$callbacks[] = $listenerCallback;
}
////////////////////////////////////////////////////////////
// Trigger the listener's callback, and push its result onto the
// response collection
$responses->push(call_user_func($listenerCallback, $e));
// If the event was asked to stop propagating, do so
if ($e->propagationIsStopped()) {
$responses->setStopped(true);
break;
}
// If the result causes our validation callback to return true,
// stop propagation
if ($callback && call_user_func($callback, $responses->last())) {
$responses->setStopped(true);
break;
}
}
///////////////////////////////////////////////////
if (isset($callbacks)) {
echo "<pre>";
var_dump($callbacks);
die();
}
///////////////////////////////////////////////////
return $responses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment