Skip to content

Commit d5c0517

Browse files
committed
[feat] handle load files of module
1 parent 27d90b2 commit d5c0517

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

src/ModuleManifest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,33 @@ protected function write(array $manifest)
160160
'<?php return '.var_export($manifest, true).';'
161161
);
162162
}
163+
164+
public function registerFiles(): void
165+
{
166+
//todo check this section store on module.php or not?
167+
$this->paths
168+
->flatMap(function ($path) {
169+
$manifests = $this->files->glob("{$path}/module.json");
170+
is_array($manifests) || $manifests = [];
171+
172+
return collect($manifests)
173+
->map(function ($manifest) {
174+
$json = $this->files->json($manifest);
175+
176+
if (! empty($json['files'])) {
177+
return [
178+
'module_directory' => dirname($manifest),
179+
...$this->files->json($manifest),
180+
];
181+
}
182+
});
183+
})
184+
->filter()
185+
->sortBy(fn ($module) => $module['priority'] ?? 0)
186+
->each(function (array $manifest) {
187+
foreach ($manifest['files'] as $file) {
188+
include_once $manifest['module_directory'].DIRECTORY_SEPARATOR.$file;
189+
}
190+
});
191+
}
163192
}

src/ModulesServiceProvider.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ protected function registerModules()
2828
{
2929
// $this->app->register(\Nwidart\Modules\Providers\BootstrapServiceProvider::class);
3030

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

33-
(new ProviderRepository($this->app, new Filesystem(), $this->getCachedModulePath()))
34-
->load($providers);
33+
(new ProviderRepository($this->app, new Filesystem, $this->getCachedModulePath()))
34+
->load($manifest->providersArray());
35+
36+
$manifest->registerFiles();
3537

3638
}
3739

0 commit comments

Comments
 (0)