|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Contains the BaseBoxServiceProvider class. |
|
7
|
|
|
* |
|
8
|
|
|
* @copyright Copyright (c) 2016 Attila Fulop |
|
9
|
|
|
* @author Attila Fulop |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* @since 2016-12-29 |
|
12
|
|
|
* |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Konekt\Concord; |
|
16
|
|
|
|
|
17
|
|
|
use Konekt\Concord\Concerns\LoadsSubmodules; |
|
18
|
|
|
|
|
19
|
|
|
abstract class BaseBoxServiceProvider extends BaseServiceProvider |
|
20
|
|
|
{ |
|
21
|
|
|
use LoadsSubmodules; |
|
22
|
|
|
|
|
23
|
|
|
protected $configFileName = 'box.php'; |
|
24
|
|
|
|
|
25
|
|
|
protected static $_kind = 'box'; |
|
26
|
|
|
|
|
27
|
|
|
public function register() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::register(); |
|
30
|
|
|
|
|
31
|
|
|
$modules = $this->config("modules", []); |
|
32
|
|
|
|
|
33
|
|
|
if (is_array($modules)) { |
|
34
|
|
|
$this->loadSubModules($modules); |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function boot() |
|
39
|
|
|
{ |
|
40
|
|
|
parent::boot(); |
|
41
|
|
|
|
|
42
|
|
|
$this->publishOwnMigrationsInASeparateGroup(); |
|
43
|
|
|
$this->publishAllSubModuleMigrations(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns the "cascade" configuration: the "apply to all submodules" config override array |
|
48
|
|
|
* |
|
49
|
|
|
* @return array |
|
50
|
|
|
*/ |
|
51
|
|
|
protected function getCascadeModuleConfiguration(): array |
|
52
|
|
|
{ |
|
53
|
|
|
$result = $this->config('cascade_config', []); |
|
54
|
|
|
|
|
55
|
|
|
return is_array($result) ? $result : []; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function publishAllSubModuleMigrations(): void |
|
59
|
|
|
{ |
|
60
|
|
|
$folder = '/' . $this->convention->migrationsFolder(); |
|
61
|
|
|
$moduleMigrationPaths = [ |
|
62
|
|
|
$this->getBasePath() . $folder => database_path('migrations') |
|
63
|
|
|
]; |
|
64
|
|
|
foreach ($this->config("modules", []) as $moduleClass => $config) { |
|
65
|
|
|
$module = $this->concord->module($this->getModuleId($moduleClass)); |
|
66
|
|
|
$moduleMigrationPaths[$module->getBasePath() . $folder] = database_path('migrations'); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$this->publishes($moduleMigrationPaths, 'migrations'); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function publishOwnMigrationsInASeparateGroup() |
|
73
|
|
|
{ |
|
74
|
|
|
$this->publishes([ |
|
75
|
|
|
$this->getBasePath() . '/' . $this->convention->migrationsFolder() => |
|
76
|
|
|
database_path('migrations') |
|
77
|
|
|
], 'own-migrations-only'); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|