Skip to content

Instantly share code, notes, and snippets.

@poisa
Last active December 24, 2015 01:29
Show Gist options
  • Save poisa/6724548 to your computer and use it in GitHub Desktop.
Save poisa/6724548 to your computer and use it in GitHub Desktop.
Generic method call using trigger()
<?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