|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelModulize\Services\Loaders; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use LaravelModulize\Contracts\ModulizerRepositoryInterface; |
|
8
|
|
|
|
|
9
|
|
|
abstract class BaseFileLoader |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Instance of Application |
|
13
|
|
|
* |
|
14
|
|
|
* @var \Illuminate\Contracts\Foundation\Application $app |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $app; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Instance of the repository |
|
20
|
|
|
* |
|
21
|
|
|
* @var \LaravelModulize\Contracts\ModulizerRepositoryInterface |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $repo; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Construct the RoutesLoader |
|
27
|
|
|
* |
|
28
|
|
|
* @param \LaravelModulize\Contracts\ModulizerRepositoryInterface $repository |
|
29
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(ModulizerRepositoryInterface $repository, Application $app) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->app = $app; |
|
34
|
|
|
$this->repo = $repository; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Go through each of the module and load the necesary files |
|
39
|
|
|
* |
|
40
|
|
|
* @return void |
|
41
|
|
|
*/ |
|
42
|
|
|
public function bootstrap(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->repo->getModules()->each(function ($module) { |
|
45
|
|
|
$this->loadFiles($module); |
|
46
|
|
|
}); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Retrieve the collection of files found for the given module |
|
51
|
|
|
* |
|
52
|
|
|
* @param string $module |
|
53
|
|
|
* @return \Illuminate\Support\Collection |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getFilesToLoad(string $module): Collection |
|
56
|
|
|
{ |
|
57
|
|
|
if (!$this->repo->filesExist($this->getFilesPath($module))) { |
|
58
|
|
|
return new Collection(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $this->repo->getFiles( |
|
62
|
|
|
$this->getFilesPath($module) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Load the files to load and register them |
|
68
|
|
|
* |
|
69
|
|
|
* @param string $module |
|
70
|
|
|
* @return void |
|
71
|
|
|
*/ |
|
72
|
|
|
abstract public function loadFiles(string $module): void; |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Retrieve the path where the files to load should be at |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $module |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
abstract public function getFilesPath(string $module): string; |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Retrieve the namespace to be used when registering the files |
|
84
|
|
|
* |
|
85
|
|
|
* @param string $module |
|
86
|
|
|
* @return string |
|
87
|
|
|
*/ |
|
88
|
|
|
abstract public function getNamespace(string $module): string; |
|
89
|
|
|
} |
|
90
|
|
|
|