Created
September 3, 2012 11:27
-
-
Save assertchris/3608668 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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