Add Plugin manager
continuous-integration/drone/tag Build is failing Details
continuous-integration/drone/push Build was killed Details

This commit is contained in:
Philipp Lang 2023-09-19 00:13:36 +02:00
parent 3d154c4154
commit be0a8a3ddb
6 changed files with 602 additions and 311 deletions

View File

@ -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()
{
//
}
}

View File

@ -79,6 +79,7 @@
"autoload": {
"psr-4": {
"App\\": "app/",
"Plugins\\": "plugins/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}

839
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -189,6 +189,7 @@ return [
App\Dav\ServiceProvider::class,
App\Setting\SettingServiceProvider::class,
App\Dashboard\DashboardServiceProvider::class,
App\Providers\PluginServiceProvider::class,
],
/*

View File

@ -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:

View File

@ -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);
}
}