initial import
This commit is contained in:
41
app/Providers/ApiPluginServiceProvider.php
Normal file
41
app/Providers/ApiPluginServiceProvider.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?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
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user