1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelModulize\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
7
|
|
|
use LaravelModulize\Services\Modulizer; |
8
|
|
|
use LaravelModulize\Services\ModulizerRepository; |
9
|
|
|
use LaravelModulize\Console\Commands\CreateModuleCommand; |
10
|
|
|
use LaravelModulize\Console\Commands\GenerateModelCommand; |
11
|
|
|
use LaravelModulize\Contracts\ModulizerRepositoryInterface; |
12
|
|
|
use LaravelModulize\Console\Commands\GenerateFactoryCommand; |
13
|
|
|
use Illuminate\Support\ServiceProvider as BaseServiceProvider; |
14
|
|
|
use LaravelModulize\Console\Commands\GenerateExceptionCommand; |
15
|
|
|
use LaravelModulize\Console\Commands\GenerateControllerCommand; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Service provider |
19
|
|
|
*/ |
20
|
|
|
class ModulizeServiceProvider extends BaseServiceProvider |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Bootstrap the application services. |
24
|
|
|
* |
25
|
|
|
* @return void |
26
|
|
|
*/ |
27
|
16 |
|
public function boot() |
28
|
|
|
{ |
29
|
16 |
|
$this->app->get('modulizer')->bootstrapFileLoaders(); |
30
|
|
|
|
31
|
16 |
|
$this->loadMigrationsFrom($this->app->get(ModulizerRepository::class)->migrations); |
32
|
|
|
|
33
|
16 |
|
$this->loadTranslations( |
34
|
16 |
|
collect($this->app->get(ModulizerRepository::class)->translations) |
35
|
|
|
); |
36
|
|
|
|
37
|
16 |
|
$this->publishes([ |
38
|
16 |
|
$this->getDefaultConfigFilePath('modulizer') => config_path('modulizer.php'), |
39
|
16 |
|
], 'config'); |
40
|
|
|
|
41
|
16 |
|
$this->loadCommands(); |
42
|
16 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Register the application services. |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
16 |
|
public function register() |
50
|
|
|
{ |
51
|
|
|
$this->app->singleton(ModulizerRepository::class, function ($app) { |
52
|
16 |
|
return new ModulizerRepository(new Filesystem(), $app); |
53
|
16 |
|
}); |
54
|
|
|
|
55
|
16 |
|
$this->app->bind( |
56
|
16 |
|
ModulizerRepositoryInterface::class, |
57
|
16 |
|
ModulizerRepository::class |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
$this->app->singleton('modulizer', function ($app) { |
61
|
16 |
|
return $app->make(Modulizer::class); |
62
|
16 |
|
}); |
63
|
|
|
|
64
|
16 |
|
$this->mergeConfigFrom( |
65
|
16 |
|
$this->getDefaultConfigFilePath('modulizer'), 'modulizer' |
66
|
|
|
); |
67
|
16 |
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get default configuration file path |
71
|
|
|
* |
72
|
|
|
* @return string |
73
|
|
|
*/ |
74
|
16 |
|
public function getDefaultConfigFilePath($configName) |
75
|
|
|
{ |
76
|
16 |
|
return realpath(__DIR__ . "/../config/{$configName}.php"); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Load translation files |
81
|
|
|
* |
82
|
|
|
* @param Collection $translations |
83
|
|
|
* @return void |
84
|
|
|
* @author Roy Freij <[email protected]> |
85
|
|
|
* @version 2019-03-04 |
86
|
|
|
*/ |
87
|
16 |
|
protected function loadTranslations(Collection $translations) |
88
|
|
|
{ |
89
|
|
|
$translations->each(function ($translationsFile) { |
90
|
|
|
$this->loadTranslationsFrom( |
91
|
|
|
$translationsFile->path, |
92
|
|
|
$translationsFile->namespace |
93
|
|
|
); |
94
|
16 |
|
}); |
95
|
16 |
|
} |
96
|
|
|
|
97
|
16 |
|
protected function loadCommands() |
98
|
|
|
{ |
99
|
16 |
|
if ($this->app->runningInConsole()) { |
100
|
16 |
|
$this->commands([ |
101
|
16 |
|
CreateModuleCommand::class, |
102
|
|
|
GenerateFactoryCommand::class, |
103
|
|
|
GenerateExceptionCommand::class, |
104
|
|
|
GenerateModelCommand::class, |
105
|
|
|
GenerateControllerCommand::class, |
106
|
|
|
]); |
107
|
|
|
} |
108
|
16 |
|
} |
109
|
|
|
} |
110
|
|
|
|