Files
ai-stylegallery/app/Providers/ApiPluginServiceProvider.php

40 lines
981 B
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))) {
PluginLoader::registerPlugin($filename, $class);
}
}
}
/**
* Bootstrap services.
*/
public function boot(): void
{
//
}
}