Last active
August 29, 2015 14:16
-
-
Save jkanclerz/1cbf63e79e305948b410 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 CallbackExecutor | |
| { | |
| protected $callback; | |
| public function __call($method, $args) | |
| { | |
| if(is_callable(array($this, $method))) { | |
| return call_user_func_array($this->$method, $args); | |
| } | |
| // else throw exception | |
| } | |
| /** | |
| * @param mixed $callback | |
| */ | |
| public function setCallback($callback) | |
| { | |
| $this->callback = $callback; | |
| } | |
| public function getSource() | |
| { | |
| for ($i = 0; $i<100; $i++) { | |
| if ($this->callback) { | |
| $this->callback($i); | |
| } | |
| } | |
| } | |
| } |
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 Provider | |
| { | |
| protected $executor; | |
| function __construct(CallbackExecutor $executor) | |
| { | |
| $this->executor = $executor; | |
| } | |
| public function getAll() | |
| { | |
| $app = $this; | |
| $this->executor->setCallback(function($i) use ($app) { | |
| return $app->process($i); | |
| }); | |
| $this->executor->getSource(); | |
| } | |
| protected function process($arg) | |
| { | |
| echo $i; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment