use IoC container to call plugin callbacks
This commit is contained in:
parent
c16ae91de0
commit
b13552e5d1
|
|
@ -10,17 +10,6 @@ use Illuminate\Support\ServiceProvider;
|
||||||
|
|
||||||
class PluginServiceProvider extends ServiceProvider
|
class PluginServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Map of event class names to callback names.
|
|
||||||
*
|
|
||||||
* @var array
|
|
||||||
*/
|
|
||||||
protected $eventCallbackMap = [
|
|
||||||
Events\PluginWasEnabled::class => 'enabled',
|
|
||||||
Events\PluginWasDeleted::class => 'deleted',
|
|
||||||
Events\PluginWasDisabled::class => 'disabled'
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bootstrap any application services.
|
* Bootstrap any application services.
|
||||||
*
|
*
|
||||||
|
|
@ -60,14 +49,18 @@ class PluginServiceProvider extends ServiceProvider
|
||||||
|
|
||||||
protected function registerPluginCallbackListener()
|
protected function registerPluginCallbackListener()
|
||||||
{
|
{
|
||||||
Event::listen(array_keys($this->eventCallbackMap), function ($event) {
|
Event::listen([
|
||||||
|
Events\PluginWasEnabled::class,
|
||||||
|
Events\PluginWasDeleted::class,
|
||||||
|
Events\PluginWasDisabled::class,
|
||||||
|
], function ($event) {
|
||||||
// call callback functions of plugin
|
// call callback functions of plugin
|
||||||
if (file_exists($filename = $event->plugin->getPath()."/callbacks.php")) {
|
if (file_exists($filename = $event->plugin->getPath()."/callbacks.php")) {
|
||||||
$callbacks = require $filename;
|
$callbacks = require $filename;
|
||||||
|
|
||||||
$callback = array_get($callbacks, $this->eventCallbackMap[get_class($event)]);
|
$callback = array_get($callbacks, get_class($event));
|
||||||
|
|
||||||
return $callback ? call_user_func($callback, $event->plugin) : null;
|
return $callback ? app()->call($callback, [$event->plugin]) : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user