Skip to content

Instantly share code, notes, and snippets.

@assertchris
Created September 3, 2012 11:27
Show Gist options
  • Select an option

  • Save assertchris/3608668 to your computer and use it in GitHub Desktop.

Select an option

Save assertchris/3608668 to your computer and use it in GitHub Desktop.
class Callbacks
{
protected $_callbacks = array();
protected function _add($name, $callback)
{
$this->_callbacks[$name] = $callback;
}
protected function _remove($name)
{
unset($this->_callbacks[$name]);
}
public function call($name, $parameters)
{
return call_user_func_array($this->_callbacks[$name], $parameters);
}
public function __construct($callbacks = null)
{
# overwrite callbacks
if ($callbacks !== null)
{
$this->_callbacks = $callbacks;
}
# define standard callbacks
$this->_add(
"return",
function($value) {
return $value;
}
);
}
}
$new = new Callbacks();
echo $new->call("return", array("hello world"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment