Skip to content

Instantly share code, notes, and snippets.

@devosc
Last active August 29, 2015 14:27
Show Gist options
  • Save devosc/8e884434160bd28602c6 to your computer and use it in GitHub Desktop.
Save devosc/8e884434160bd28602c6 to your computer and use it in GitHub Desktop.
<?php
$plugin = $this->plugin($plugin, function($plugin) use($args, $callback) {
if (!is_callable($plugin)) {
return $this->call('service:event', [$plugin]);
}
return $plugin;
});
public function call($config, array $args = [], callable $callback = null)
{
if (!is_string($config)) {
return $config instanceof Event ? $this->trigger($config, $args, $callback ?: $this)
: $this->invoke($config, $args, $callback);
}
$config = explode(Args::CALL_SEPARATOR, $config);
$plugin = array_shift($config);
$method = array_pop($config);
$plugin = $this->plugin($plugin, function($plugin) use($args, $callback) {
if (!is_callable($plugin)) {
return $this->call('service:event', [$plugin]);
}
return $plugin;
});
if ($plugin instanceof Event) {
return $this->trigger($plugin, $args, $callback ?: $this);
}
foreach($config as $name) {
$plugin = $this->invoke([$plugin, $name], $args, $callback);
}
return $this->invoke($method ? [$plugin, $method] : $plugin, $args, $callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment