55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\CMS\ModuleManager\Providers;
|
|
|
|
use App\CMS\Repositories\Module as ModuleRepository;
|
|
use Illuminate\Database\QueryException;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class ModuleManager extends ServiceProvider
|
|
{
|
|
/**
|
|
* Bootstrap the application services.
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
// this service provider needs published config - config is merged right after this service provider
|
|
try {
|
|
$modules = app(ModuleRepository::class)->all();
|
|
} catch (QueryException $e) {
|
|
return;
|
|
}
|
|
|
|
// iterate over all modules and enable or disable them
|
|
foreach ($modules as $module) {
|
|
if (isset($module->module_settings['providers']) && !empty($module->module_settings['providers'])) {
|
|
foreach ($module->module_settings['providers'] as $provider) {
|
|
$this->app->register($provider);
|
|
}
|
|
}
|
|
|
|
// include files (if any)
|
|
if (isset($module->module_settings['files']) && !empty($module->module_settings['files'])) {
|
|
foreach ($module->module_settings['files'] as $file) {
|
|
$path = config('modules.paths.modules') . '/' . $module->static_name . '/' . $file;
|
|
|
|
if (!file_exists($path)) {
|
|
$path = base_path($file);
|
|
}
|
|
|
|
@include_once $path;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register the application services.
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
}
|
|
}
|