|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace LaravelModulize\Services; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Contracts\Foundation\Application; |
|
6
|
|
|
use Illuminate\Support\Collection; |
|
7
|
|
|
use LaravelModulize\Contracts\ModulizerRepositoryInterface; |
|
8
|
|
|
use LaravelModulize\Services\Loaders\FactoriesLoader; |
|
9
|
|
|
use LaravelModulize\Services\Loaders\MigrationsLoader; |
|
10
|
|
|
use LaravelModulize\Services\Loaders\RoutesLoader; |
|
11
|
|
|
use LaravelModulize\Services\Loaders\TranslationsLoader; |
|
12
|
|
|
|
|
13
|
|
|
class Modulizer |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @var \Illuminate\Contracts\Foundation\Application |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $app; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Repository |
|
22
|
|
|
* |
|
23
|
|
|
* @var \LaravelModulize\Contracts\ModulizerRepositoryInterface |
|
24
|
|
|
*/ |
|
25
|
|
|
public $repository; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Register the file loaders to be bootstrapped |
|
29
|
|
|
* |
|
30
|
|
|
* @var array |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $fileLoaders = [ |
|
33
|
|
|
RoutesLoader::class, |
|
34
|
|
|
MigrationsLoader::class, |
|
35
|
|
|
FactoriesLoader::class, |
|
36
|
|
|
TranslationsLoader::class, |
|
37
|
|
|
]; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Modulizer constructor |
|
41
|
|
|
* |
|
42
|
|
|
* @param \LaravelModulize\Contracts\ModulizerRepositoryInterface $repository |
|
43
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
44
|
|
|
*/ |
|
45
|
16 |
|
public function __construct(ModulizerRepositoryInterface $repository, Application $app) |
|
46
|
|
|
{ |
|
47
|
16 |
|
$this->app = $app; |
|
48
|
16 |
|
$this->repository = $repository; |
|
49
|
16 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Bootstrap the file loaders for route, migration and translation files |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
16 |
|
public function bootstrapFileLoaders() |
|
57
|
|
|
{ |
|
58
|
16 |
|
if ($this->repository->hasModules()) { |
|
59
|
|
|
$this->getFileLoaders()->each(function ($fileLoader) { |
|
60
|
|
|
$this->call($fileLoader)->bootstrap(); |
|
61
|
|
|
}); |
|
62
|
|
|
} |
|
63
|
16 |
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Create a new instance of the given class through the service container |
|
67
|
|
|
* |
|
68
|
|
|
* @param string $class |
|
69
|
|
|
* @return mixed |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function call(string $class) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->app->make($class); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Collect the fileLoaders for that should be bootstrapped |
|
78
|
|
|
* |
|
79
|
|
|
* @return \Illuminate\Support\Collection |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function getFileLoaders(): Collection |
|
82
|
|
|
{ |
|
83
|
|
|
return collect($this->fileLoaders); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|