65 lines
1.8 KiB
PHP
65 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Providers;
|
|
|
|
use Illuminate\Contracts\Filesystem\FileNotFoundException;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Pingpong\Modules\Json;
|
|
|
|
class SubmodulesManager extends ServiceProvider
|
|
{
|
|
/**
|
|
* Boot submodules
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
$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
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Register the service provider.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register()
|
|
{
|
|
// TODO: Implement register() method.
|
|
}
|
|
} |