1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Core\Providers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\ServiceProvider; |
6
|
|
|
|
7
|
|
|
class BlogCoreServiceProvider extends ServiceProvider |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* Bootstrap services. |
11
|
|
|
* |
12
|
|
|
* @return void |
13
|
|
|
*/ |
14
|
|
|
public function boot(): void |
15
|
|
|
{ |
16
|
|
|
$this->registerAssetLoading(); |
17
|
|
|
|
18
|
|
|
$this->registerAssetPublishing(); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Register services. |
23
|
|
|
* |
24
|
|
|
* @return void |
25
|
|
|
*/ |
26
|
|
|
public function register(): void |
27
|
|
|
{ |
28
|
|
|
$this->registerConfigs(); |
29
|
|
|
|
30
|
|
|
$this->registerCommands(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Get the services provided by the provider. |
35
|
|
|
* |
36
|
|
|
* @return null|array<string> |
37
|
|
|
*/ |
38
|
|
|
public function provides(): ?array |
39
|
|
|
{ |
40
|
|
|
return ['blog-core']; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return void |
45
|
|
|
*/ |
46
|
|
|
protected function registerCommands(): void |
47
|
|
|
{ |
48
|
|
|
$this->commands([ |
49
|
|
|
\CSlant\Blog\Core\Commands\ListProvidersCommand::class, |
50
|
|
|
\CSlant\Blog\Core\Commands\CheckSqlModeCommand::class, |
51
|
|
|
]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return void |
56
|
|
|
*/ |
57
|
|
|
protected function registerAssetPublishing(): void |
58
|
|
|
{ |
59
|
|
|
$configPath = __DIR__.'/../../config/blog-core.php'; |
60
|
|
|
$this->publishes([ |
61
|
|
|
$configPath => config_path('blog-core.php'), |
62
|
|
|
], 'config'); |
63
|
|
|
|
64
|
|
|
$this->publishes([ |
65
|
|
|
__DIR__.'/../../lang' => resource_path('lang/packages/blog-core'), |
66
|
|
|
], 'lang'); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return void |
71
|
|
|
*/ |
72
|
|
|
protected function registerAssetLoading(): void |
73
|
|
|
{ |
74
|
|
|
$routePath = __DIR__.'/../../routes/blog-core.php'; |
75
|
|
|
if (file_exists($routePath)) { |
76
|
|
|
$this->loadRoutesFrom($routePath); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$this->loadTranslationsFrom(__DIR__.'/../../lang', 'blog-core'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Register configs. |
84
|
|
|
* |
85
|
|
|
* @return void |
86
|
|
|
*/ |
87
|
|
|
protected function registerConfigs(): void |
88
|
|
|
{ |
89
|
|
|
$configDir = __DIR__.'/../../config'; |
90
|
|
|
$files = scandir($configDir); |
91
|
|
|
|
92
|
|
|
if ($files === false) { |
93
|
|
|
return; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
foreach ($files as $file) { |
97
|
|
|
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') { |
98
|
|
|
$configName = pathinfo($file, PATHINFO_FILENAME); |
99
|
|
|
$configPath = $configDir.'/'.$file; |
100
|
|
|
|
101
|
|
|
if (file_exists(config_path($configName.'.php'))) { |
|
|
|
|
102
|
|
|
config()->set($configName, array_merge( |
|
|
|
|
103
|
|
|
is_array(config($configName)) ? config($configName) : [], |
|
|
|
|
104
|
|
|
require $configPath |
105
|
|
|
)); |
106
|
|
|
} else { |
107
|
|
|
$this->mergeConfigFrom($configPath, $configName); |
|
|
|
|
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|