Skip to content

Instantly share code, notes, and snippets.

@jkanclerz
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save jkanclerz/1cbf63e79e305948b410 to your computer and use it in GitHub Desktop.

Select an option

Save jkanclerz/1cbf63e79e305948b410 to your computer and use it in GitHub Desktop.
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);
}
}
}
}
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