FEATURE: add service provider for generating module.json
This commit is contained in:
@@ -15,7 +15,8 @@ class Module extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'handler',
|
'handler',
|
||||||
'name',
|
'name',
|
||||||
'description'
|
'description',
|
||||||
|
'alias'
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $guarded = [];
|
protected $guarded = [];
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Models\Module;
|
||||||
|
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
|
||||||
|
$modules = Module::get();
|
||||||
|
|
||||||
|
// iterate over all modules and enable or disable them
|
||||||
|
foreach ($modules as $module) {
|
||||||
|
$this->createModulesJson($module);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register the application services.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function register()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read config file and merge it with module config in database.
|
||||||
|
*
|
||||||
|
* This method REQUIRES published config of given module (otherwise config(modulename) is not available)!
|
||||||
|
*
|
||||||
|
* @param Module $module
|
||||||
|
*
|
||||||
|
* @throws \ErrorException when module.json is not writable
|
||||||
|
*/
|
||||||
|
private function createModulesJson(Module $module)
|
||||||
|
{
|
||||||
|
$data = config($module->alias);
|
||||||
|
$data['active'] = $module->enabled;
|
||||||
|
|
||||||
|
// path to module.json
|
||||||
|
$path = config('modules.paths.modules') . DIRECTORY_SEPARATOR . $data['name'] . DIRECTORY_SEPARATOR . 'module.json';
|
||||||
|
|
||||||
|
if (!is_writable($path)) {
|
||||||
|
throw new \ErrorException('Cannot write to ' . $path . '. Module ' . $data['name'] . ' cannot be enabled.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// create file
|
||||||
|
file_put_contents($path, json_encode($data));
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-2
@@ -97,8 +97,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
'upload_url' => env('UPLOAD_URL', PHP_SAPI === 'cli' ? '' : url('uploads')),
|
'upload_url' => env('UPLOAD_URL', PHP_SAPI === 'cli' ? '' : url('uploads')),
|
||||||
'thumbnail_url' => env('THUMBNAIL_URL', PHP_SAPI === 'cli' ? '' : url('uploads/thumbnails')),
|
'thumbnail_url' => env('THUMBNAIL_URL', PHP_SAPI === 'cli' ? '' : url('uploads/thumbnails')),
|
||||||
|
'theme' => 'default_theme',
|
||||||
'theme' => 'default_theme',
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Logging Configuration
|
| Logging Configuration
|
||||||
@@ -150,6 +149,8 @@ return [
|
|||||||
Illuminate\Translation\TranslationServiceProvider::class,
|
Illuminate\Translation\TranslationServiceProvider::class,
|
||||||
Illuminate\Validation\ValidationServiceProvider::class,
|
Illuminate\Validation\ValidationServiceProvider::class,
|
||||||
Illuminate\View\ViewServiceProvider::class,
|
Illuminate\View\ViewServiceProvider::class,
|
||||||
|
// this class must be before ModulesServiceProvider from PingPong, because it handles files module.json
|
||||||
|
App\Providers\ModuleManager::class,
|
||||||
Pingpong\Modules\ModulesServiceProvider::class,
|
Pingpong\Modules\ModulesServiceProvider::class,
|
||||||
Pingpong\Menus\MenusServiceProvider::class,
|
Pingpong\Menus\MenusServiceProvider::class,
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user