1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Rawilk\LaravelModules; |
4
|
|
|
|
5
|
|
|
use Rawilk\LaravelModules\Contracts\Activator; |
6
|
|
|
use Rawilk\LaravelModules\Contracts\Repository; |
7
|
|
|
use Rawilk\LaravelModules\Laravel\LaravelFileRepository; |
8
|
|
|
use Rawilk\LaravelModules\Support\Stub; |
9
|
|
|
|
10
|
|
|
class LaravelModulesServiceProvider extends ModuleServiceProvider |
11
|
|
|
{ |
12
|
|
|
public function boot(): void |
13
|
|
|
{ |
14
|
|
|
$this->registerNamespaces(); |
15
|
|
|
$this->registerModuleModel(); |
16
|
|
|
$this->registerModules(); |
17
|
|
|
$this->publishMigrations(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
public function register(): void |
21
|
|
|
{ |
22
|
|
|
$this->registerServices(); |
23
|
|
|
$this->setupStubPath(); |
24
|
|
|
$this->registerProviders(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function setupStubPath(): void |
28
|
|
|
{ |
29
|
|
|
Stub::setBasePath(__DIR__ . '/Commands/stubs'); |
30
|
|
|
|
31
|
|
|
$this->app->booted(static function ($app) { |
32
|
|
|
/** @var \Rawilk\LaravelModules\Contracts\Repository $moduleRepository */ |
33
|
|
|
$moduleRepository = $app[Repository::class]; |
34
|
|
|
|
35
|
|
|
if ($moduleRepository->config('stubs.enabled')) { |
36
|
|
|
Stub::setBasePath($moduleRepository->config('stubs.path')); |
37
|
|
|
} |
38
|
|
|
}); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
protected function registerServices(): void |
42
|
|
|
{ |
43
|
|
|
$this->app->singleton(Repository::class, static function ($app) { |
44
|
|
|
$path = $app['config']->get('modules.paths.modules'); |
45
|
|
|
|
46
|
|
|
return new LaravelFileRepository($app, $path); |
47
|
|
|
}); |
48
|
|
|
|
49
|
|
|
$this->app->singleton(Activator::class, static function ($app) { |
50
|
|
|
$activator = $app['config']->get('modules.activator'); |
51
|
|
|
$class = $app['config']->get('modules.activators.' . $activator)['class']; |
52
|
|
|
|
53
|
|
|
return new $class($app); |
54
|
|
|
}); |
55
|
|
|
|
56
|
|
|
$this->app->alias(Repository::class, 'modules'); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|