Add composer support for plugins

This commit is contained in:
printempw 2018-06-28 23:32:27 +08:00
parent 0a307e9221
commit 86a5631431
2 changed files with 23 additions and 0 deletions

View File

@ -38,6 +38,11 @@ class PluginServiceProvider extends ServiceProvider
$this->registerPluginCallbackListener();
$this->registerClassAutoloader($src_paths);
// Register plugin's own composer autoloader
foreach ($plugins->getEnabledComposerAutoloaders() as $autoloader) {
require $autoloader;
}
$bootstrappers = $plugins->getEnabledBootstrappers();
foreach ($bootstrappers as $file) {

View File

@ -219,6 +219,24 @@ class PluginManager
return $bootstrappers;
}
/**
* Loads composer autoloader for the enabled plugins if exists.
*
* @return Collection
*/
public function getEnabledComposerAutoloaders()
{
$autoloaders = new Collection;
foreach ($this->getEnabledPlugins() as $plugin) {
if ($this->filesystem->exists($file = $plugin->getPath().'/vendor/autoload.php')) {
$autoloaders->push($file);
}
}
return $autoloaders;
}
/**
* The id's of the enabled plugins.
*