1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Laravel Love. |
5
|
|
|
* |
6
|
|
|
* (c) Anton Komarev <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cog\Laravel\Love; |
15
|
|
|
|
16
|
|
|
use Cog\Laravel\Love\Console\Commands\ReactionTypeAdd; |
17
|
|
|
use Cog\Laravel\Love\Console\Commands\Recount; |
18
|
|
|
use Cog\Laravel\Love\Console\Commands\RegisterReactants; |
19
|
|
|
use Cog\Laravel\Love\Console\Commands\RegisterReacters; |
20
|
|
|
use Cog\Laravel\Love\Console\Commands\SetupReactable; |
21
|
|
|
use Cog\Laravel\Love\Console\Commands\SetupReacterable; |
22
|
|
|
use Cog\Laravel\Love\Console\Commands\UpgradeV5ToV6; |
23
|
|
|
use Cog\Laravel\Love\Console\Commands\UpgradeV7ToV8; |
24
|
|
|
use Cog\Laravel\Love\Reaction\Models\Reaction; |
25
|
|
|
use Cog\Laravel\Love\Reaction\Observers\ReactionObserver; |
26
|
|
|
use Illuminate\Support\Facades\Config; |
27
|
|
|
use Illuminate\Support\ServiceProvider; |
28
|
|
|
|
29
|
|
|
final class LoveServiceProvider extends ServiceProvider |
30
|
|
|
{ |
31
|
|
|
/** |
32
|
|
|
* Register the service provider. |
33
|
|
|
*/ |
34
|
|
|
public function register(): void |
35
|
|
|
{ |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Bootstrap the application events. |
40
|
|
|
*/ |
41
|
|
|
public function boot(): void |
42
|
|
|
{ |
43
|
|
|
$this->configure(); |
44
|
|
|
$this->registerConsoleCommands(); |
45
|
|
|
$this->registerObservers(); |
46
|
|
|
$this->registerPublishes(); |
47
|
|
|
$this->registerMigrations(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Determine if we should register default migrations. |
52
|
|
|
*/ |
53
|
|
|
private function shouldLoadDefaultMigrations(): bool |
54
|
|
|
{ |
55
|
|
|
return Config::get('love.load_default_migrations', true); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Register Love's models observers. |
60
|
|
|
*/ |
61
|
|
|
private function registerObservers(): void |
62
|
|
|
{ |
63
|
|
|
Reaction::observe(ReactionObserver::class); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Register Love's console commands. |
68
|
|
|
*/ |
69
|
|
|
private function registerConsoleCommands(): void |
70
|
|
|
{ |
71
|
|
|
if ($this->app->runningInConsole()) { |
72
|
|
|
$this->commands([ |
73
|
|
|
ReactionTypeAdd::class, |
74
|
|
|
Recount::class, |
75
|
|
|
SetupReactable::class, |
76
|
|
|
SetupReacterable::class, |
77
|
|
|
RegisterReactants::class, |
78
|
|
|
RegisterReacters::class, |
79
|
|
|
UpgradeV5ToV6::class, |
80
|
|
|
UpgradeV7ToV8::class, |
81
|
|
|
]); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Setup the resource publishing groups for Love. |
87
|
|
|
*/ |
88
|
|
|
private function registerPublishes(): void |
89
|
|
|
{ |
90
|
|
|
if ($this->app->runningInConsole()) { |
91
|
|
|
$this->publishes([ |
92
|
|
|
__DIR__ . '/../config/love.php' => config_path('love.php'), |
93
|
|
|
], 'love-config'); |
94
|
|
|
|
95
|
|
|
$this->publishes([ |
96
|
|
|
__DIR__ . '/../database/migrations' => database_path('migrations'), |
97
|
|
|
], 'love-migrations'); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Register the Love migrations. |
103
|
|
|
*/ |
104
|
|
|
private function registerMigrations(): void |
105
|
|
|
{ |
106
|
|
|
if ($this->app->runningInConsole() && $this->shouldLoadDefaultMigrations()) { |
107
|
|
|
$this->loadMigrationsFrom(__DIR__ . '/../database/migrations'); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Merge Love configuration with the application configuration. |
113
|
|
|
*/ |
114
|
|
|
private function configure(): void |
115
|
|
|
{ |
116
|
|
|
if (!$this->app->configurationIsCached()) { |
117
|
|
|
$this->mergeConfigFrom(__DIR__ . '/../config/love.php', 'love'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|