FEATURE: add support for submodules

This commit is contained in:
Michal Kváček
2016-08-15 20:46:54 +02:00
parent d54f160d6a
commit fa21c407b4
4 changed files with 150 additions and 0 deletions
+55
View File
@@ -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
}
}
}
}
}