Skip to content

Commit

Permalink
Merge pull request #1947 from alissn/FixLoadModuleFiles
Browse files Browse the repository at this point in the history
[feat] handle load files of module
  • Loading branch information
dcblogdev authored Sep 17, 2024
2 parents 8bee9dc + d5c0517 commit d001c04
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
29 changes: 29 additions & 0 deletions src/ModuleManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,33 @@ protected function write(array $manifest)
'<?php return '.var_export($manifest, true).';'
);
}

public function registerFiles(): void
{
//todo check this section store on module.php or not?
$this->paths
->flatMap(function ($path) {
$manifests = $this->files->glob("{$path}/module.json");
is_array($manifests) || $manifests = [];

return collect($manifests)
->map(function ($manifest) {
$json = $this->files->json($manifest);

if (! empty($json['files'])) {
return [
'module_directory' => dirname($manifest),
...$this->files->json($manifest),
];
}
});
})
->filter()
->sortBy(fn ($module) => $module['priority'] ?? 0)
->each(function (array $manifest) {
foreach ($manifest['files'] as $file) {
include_once $manifest['module_directory'].DIRECTORY_SEPARATOR.$file;
}
});
}
}
8 changes: 5 additions & 3 deletions src/ModulesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ protected function registerModules()
{
// $this->app->register(\Nwidart\Modules\Providers\BootstrapServiceProvider::class);

$providers = app()->make(ModuleManifest::class)->providersArray();
$manifest = app()->make(ModuleManifest::class);

(new ProviderRepository($this->app, new Filesystem(), $this->getCachedModulePath()))
->load($providers);
(new ProviderRepository($this->app, new Filesystem, $this->getCachedModulePath()))
->load($manifest->providersArray());

$manifest->registerFiles();

}

Expand Down

0 comments on commit d001c04

Please sign in to comment.