Add Plugin manager
This commit is contained in:
parent
3d154c4154
commit
be0a8a3ddb
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PluginServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
foreach (glob(base_path('plugins/*/ServiceProvider.php')) as $file) {
|
||||
$cls = (string) str($file)
|
||||
->replace(base_path('plugins/'), '')
|
||||
->replaceMatches('/\.php$/', '')
|
||||
->replace('/', '\\');
|
||||
$this->app->register('Plugins\\'.$cls);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
|
@ -79,6 +79,7 @@
|
|||
"autoload": {
|
||||
"psr-4": {
|
||||
"App\\": "app/",
|
||||
"Plugins\\": "plugins/",
|
||||
"Database\\Factories\\": "database/factories/",
|
||||
"Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -189,6 +189,7 @@ return [
|
|||
App\Dav\ServiceProvider::class,
|
||||
App\Setting\SettingServiceProvider::class,
|
||||
App\Dashboard\DashboardServiceProvider::class,
|
||||
App\Providers\PluginServiceProvider::class,
|
||||
],
|
||||
|
||||
/*
|
||||
|
|
|
@ -32,6 +32,7 @@ services:
|
|||
REDIS_HOST: redis
|
||||
volumes:
|
||||
- ./data/storage:/app/storage/app
|
||||
- ./data/plugins:/app/plugins
|
||||
- ./data/cookies:/app/packages/laravel-nami/.cookies
|
||||
|
||||
horizon:
|
||||
|
@ -53,6 +54,7 @@ services:
|
|||
REDIS_HOST: redis
|
||||
volumes:
|
||||
- ./data/storage:/app/storage/app
|
||||
- ./data/plugins:/app/plugins
|
||||
- ./data/cookies:/app/packages/laravel-nami/.cookies
|
||||
|
||||
schedule:
|
||||
|
@ -74,6 +76,7 @@ services:
|
|||
REDIS_HOST: redis
|
||||
volumes:
|
||||
- ./data/storage:/app/storage/app
|
||||
- ./data/plugins:/app/plugins
|
||||
- ./data/cookies:/app/packages/laravel-nami/.cookies
|
||||
|
||||
db:
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Unit\Plugin;
|
||||
|
||||
use Tests\TestCase;
|
||||
|
||||
class PluginTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp(): void
|
||||
{}
|
||||
|
||||
public function testItCanRegisterAPlugin(): void
|
||||
{
|
||||
$pluginsPath = __DIR__.'/../../../plugins/Test';
|
||||
@mkdir($pluginsPath);
|
||||
|
||||
file_put_contents($pluginsPath.'/ServiceProvider.php', '<?php
|
||||
namespace Plugins\Test;
|
||||
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
|
||||
class ServiceProvider extends BaseServiceProvider
|
||||
{
|
||||
public function register() {}
|
||||
public function boot() {}
|
||||
}');
|
||||
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->assertInstanceOf('Plugins\\Test\\ServiceProvider', app()->getProvider('Plugins\\Test\\ServiceProvider'));
|
||||
|
||||
array_map(fn ($file) => unlink($file), glob($pluginsPath.'/*'));
|
||||
rmdir($pluginsPath);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue