diff --git a/app/Providers/SubmodulesManager.php b/app/Providers/SubmodulesManager.php new file mode 100644 index 00000000..26408faf --- /dev/null +++ b/app/Providers/SubmodulesManager.php @@ -0,0 +1,55 @@ +getPath(); + $config = new Json($modulePath . DIRECTORY_SEPARATOR . 'module.json'); + + // Does this module specify any providers? If not, consider this module with submodules and register them + if ($config->get('providers')) { + continue; + } + + $submodules = \File::directories($modulePath); + + foreach ($submodules as $submodulePath) { + try { + $config = new Json($submodulePath . DIRECTORY_SEPARATOR . 'module.json'); + + if (!$config->get('active')) { + continue; + } + + $serviceProviders = $config->get('providers', []); + foreach ($serviceProviders as $serviceProvider) { + $this->app->register($serviceProvider); + } + + $initFiles = $config->get('files', []); + + foreach ($initFiles as $file) { + @include $submodulePath . DIRECTORY_SEPARATOR . $file; + } + } catch (FileNotFoundException $e) { + // ignore missing module and do not register this submodule + } + } + } + } +} \ No newline at end of file diff --git a/config/app.php b/config/app.php index 0eb76474..443ea671 100644 --- a/config/app.php +++ b/config/app.php @@ -154,6 +154,8 @@ return [ App\Providers\ModuleManager::class, Pingpong\Modules\ModulesServiceProvider::class, Pingpong\Menus\MenusServiceProvider::class, + App\Providers\SubmodulesManager::class, + Franzose\ClosureTable\ClosureTableServiceProvider::class, \Watson\Sitemap\SitemapServiceProvider::class, /* diff --git a/database/migrations/2016_08_14_165211_MakeModuleHandlerNullable.php b/database/migrations/2016_08_14_165211_MakeModuleHandlerNullable.php new file mode 100644 index 00000000..836062e0 --- /dev/null +++ b/database/migrations/2016_08_14_165211_MakeModuleHandlerNullable.php @@ -0,0 +1,47 @@ +string('handler') + ->nullable(true) + ->change(); + + $table->string('alias') + ->nullable(true) + ->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('modules', function (Blueprint $table) { + + $table->string('alias') + ->nullable(false) + ->change(); + + // somehow I cannot change it back, sorry... + +// $table->string('handler') +// ->nullable(false) +// ->change(); + }); + } +} diff --git a/database/migrations/2016_08_15_183157_AddParentModuleIdToModules.php b/database/migrations/2016_08_15_183157_AddParentModuleIdToModules.php new file mode 100644 index 00000000..48e090ae --- /dev/null +++ b/database/migrations/2016_08_15_183157_AddParentModuleIdToModules.php @@ -0,0 +1,46 @@ +integer('parent_id') + ->nullable(true) + ->comment('Parent module ID (when module is submodule)') + ->after('id'); + $table->boolean('has_submodules') + ->default(false); + + $table->foreign('parent_id') + ->references('id') + ->on('modules') + ->onDelete('cascade') + ->onUpdate('cascade'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('modules', function (Blueprint $table) { + $table->dropForeign('modules_parent_id_foreign'); + + $table->dropColumn('has_submodules'); + $table->dropColumn('parent_id'); + }); + } +}