41 lines
1.0 KiB
PHP
41 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Support\ServiceProvider;
|
|
use App\Api\Plugins\PluginLoader;
|
|
use App\Api\Plugins\ApiPluginInterface;
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
class ApiPluginServiceProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register services.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$path = app_path('Api/Plugins');
|
|
$files = File::files($path);
|
|
|
|
foreach ($files as $file) {
|
|
$filename = $file->getFilenameWithoutExtension();
|
|
if (in_array($filename, ['ApiPluginInterface', 'PluginLoader'])) {
|
|
continue;
|
|
}
|
|
|
|
$class = 'App\\Api\\Plugins\\' . $filename;
|
|
if (class_exists($class) && in_array(ApiPluginInterface::class, class_implements($class))) {
|
|
$instance = new $class();
|
|
PluginLoader::registerPlugin($instance->getIdentifier(), $class);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Bootstrap services.
|
|
*/
|
|
public function boot(): void
|
|
{
|
|
//
|
|
}
|
|
} |