Created
June 15, 2013 22:30
-
-
Save nclundsten/5789823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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