Register service providers of plugins
This commit is contained in:
parent
43ede5b274
commit
72aa2c39ac
@ -141,6 +141,7 @@ class PluginManager
|
||||
);
|
||||
$this->loadVendor($enabled);
|
||||
$this->loadViewsAndTranslations($enabled);
|
||||
$this->registerServiceProviders($enabled);
|
||||
$this->loadBootstrapper($enabled);
|
||||
$this->registerLifecycleHooks();
|
||||
|
||||
@ -202,6 +203,22 @@ class PluginManager
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Collection $enabled
|
||||
*/
|
||||
protected function registerServiceProviders($enabled)
|
||||
{
|
||||
$enabled->each(function ($plugin) {
|
||||
$providers = Arr::get($plugin->getManifest(), 'enchants.providers', []);
|
||||
array_walk($providers, function ($provider) use ($plugin) {
|
||||
$class = Str::start(Str::finish($provider, 'ServiceProvider'), $plugin->namespace.'\\');
|
||||
if (class_exists($class)) {
|
||||
$this->app->register($class);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Load plugin's bootstrapper.
|
||||
*
|
||||
|
@ -1,5 +1,10 @@
|
||||
{
|
||||
"name": "fake",
|
||||
"version": "0.0.0",
|
||||
"namespace": "Fake"
|
||||
"namespace": "Fake",
|
||||
"enchants": {
|
||||
"providers": [
|
||||
"Fake"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
13
storage/mocks/fake-plugin/src/FakeServiceProvider.php
Normal file
13
storage/mocks/fake-plugin/src/FakeServiceProvider.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Fake;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class FakeServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function boot()
|
||||
{
|
||||
event('provider.loaded');
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Fake;
|
||||
|
||||
class Faker
|
||||
{
|
||||
}
|
@ -341,7 +341,22 @@ class PluginManagerTest extends TestCase
|
||||
|
||||
$this->assertFalse(class_exists('Fake\Faker'));
|
||||
$manager = $this->rebootPluginManager(app('plugins'));
|
||||
$this->assertTrue(class_exists('Fake\Faker'));
|
||||
$this->assertTrue(class_exists('Fake\FakeServiceProvider'));
|
||||
|
||||
config(['plugins.directory' => $dir]);
|
||||
option(['plugins_enabled' => '[]']);
|
||||
}
|
||||
|
||||
public function testRegisterServiceProviders()
|
||||
{
|
||||
Event::fake();
|
||||
|
||||
$dir = config('plugins.directory');
|
||||
config(['plugins.directory' => storage_path('mocks')]);
|
||||
option(['plugins_enabled' => json_encode([['name' => 'fake', 'version' => '0.0.0']])]);
|
||||
|
||||
$manager = $this->rebootPluginManager(app('plugins'));
|
||||
Event::assertDispatched('provider.loaded');
|
||||
|
||||
config(['plugins.directory' => $dir]);
|
||||
option(['plugins_enabled' => '[]']);
|
||||
|
Loading…
Reference in New Issue
Block a user