Last active
December 24, 2015 01:29
-
-
Save poisa/6724548 to your computer and use it in GitHub Desktop.
Generic method call using trigger()
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
<?php | |
public function findMemberById($id) | |
{ | |
$params = $this->getEventManager()->prepareArgs(compact(func_get_args())); | |
$result = $this->getEventManager()->trigger(__FUNCTION__ . '.pre', $this, $params, function ($listenerOutput) { | |
return ($listenerOutput != null); | |
}); | |
extract((array)$params); | |
if ($result->stopped()) { | |
return $result->last(); | |
} | |
// Expensive calls here | |
$params['__RESULT__'] = $calculatedResult; | |
$this->getEventManager()->trigger(__FUNCTION__ . '.post', $this, $params); | |
return $calculatedResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment