|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Turahe\Likeable; |
|
4
|
|
|
|
|
5
|
|
|
use Turahe\Likeable\Models\Like; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider; |
|
7
|
|
|
use Turahe\Likeable\Models\LikeCounter; |
|
8
|
|
|
use Turahe\Likeable\Observers\LikeObserver; |
|
9
|
|
|
use Turahe\Likeable\Services\LikeableService; |
|
10
|
|
|
use Turahe\Likeable\Console\LikeableRecountCommand; |
|
11
|
|
|
use Turahe\Likeable\Contracts\Like as LikeContract; |
|
12
|
|
|
use Turahe\Likeable\Contracts\LikeCounter as LikeCounterContract; |
|
13
|
|
|
use Turahe\Likeable\Contracts\LikeableService as LikeableServiceContract; |
|
14
|
|
|
|
|
15
|
|
|
class LikeableServiceProvider extends ServiceProvider |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Bootstrap the application events. |
|
19
|
|
|
* |
|
20
|
|
|
* @return void |
|
21
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
|
22
|
|
|
*/ |
|
23
|
|
|
public function boot() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->registerConsoleCommands(); |
|
26
|
|
|
$this->registerObservers(); |
|
27
|
|
|
$this->registerPublishes(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Register the service provider. |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
public function register() |
|
36
|
|
|
{ |
|
37
|
|
|
$this->registerContracts(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Register Likeable's models observers. |
|
42
|
|
|
* |
|
43
|
|
|
* @return void |
|
44
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException |
|
45
|
|
|
*/ |
|
46
|
|
|
protected function registerObservers() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->app->make(LikeContract::class)->observe(LikeObserver::class); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Register Likeable's console commands. |
|
53
|
|
|
* |
|
54
|
|
|
* @return void |
|
55
|
|
|
*/ |
|
56
|
|
|
protected function registerConsoleCommands() |
|
57
|
|
|
{ |
|
58
|
|
|
if ($this->app->runningInConsole()) { |
|
59
|
|
|
$this->commands([ |
|
60
|
|
|
LikeableRecountCommand::class, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Register Likeable's classes in the container. |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function registerContracts() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->app->bind(LikeContract::class, Like::class); |
|
73
|
|
|
$this->app->bind(LikeCounterContract::class, LikeCounter::class); |
|
74
|
|
|
$this->app->singleton(LikeableServiceContract::class, LikeableService::class); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Setup the resource publishing groups for Likeable. |
|
79
|
|
|
* |
|
80
|
|
|
* @return void |
|
81
|
|
|
*/ |
|
82
|
|
|
protected function registerPublishes() |
|
83
|
|
|
{ |
|
84
|
|
|
$databasePath = __DIR__.'/../migrations'; |
|
85
|
|
|
$this->loadMigrationsFrom($databasePath); |
|
86
|
|
|
|
|
87
|
|
|
if ($this->app->runningInConsole()) { |
|
88
|
|
|
$this->publishes([ |
|
89
|
|
|
__DIR__.'./../migrations' => database_path('migrations'), |
|
90
|
|
|
], 'migrations'); |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|