FEATURE: add support for submodules
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Pingpong\Modules\Json;
|
||||
|
||||
class SubmodulesManager extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register the service provider.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
$enabledModules = \Module::enabled();
|
||||
|
||||
foreach ($enabledModules as $module) {
|
||||
$modulePath = $module->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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user