|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Arcanedev\LaravelMessenger; |
|
6
|
|
|
|
|
7
|
|
|
use Arcanedev\Support\Providers\PackageServiceProvider; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class LaravelMessengerServiceProvider |
|
11
|
|
|
* |
|
12
|
|
|
* @package Arcanedev\LaravelMessenger |
|
13
|
|
|
* @author ARCANEDEV <[email protected]> |
|
14
|
|
|
*/ |
|
15
|
|
|
class LaravelMessengerServiceProvider extends PackageServiceProvider |
|
16
|
|
|
{ |
|
17
|
|
|
/* ----------------------------------------------------------------- |
|
18
|
|
|
| Properties |
|
19
|
|
|
| ----------------------------------------------------------------- |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Package name. |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $package = 'messenger'; |
|
28
|
|
|
|
|
29
|
|
|
/* ----------------------------------------------------------------- |
|
30
|
|
|
| Main Methods |
|
31
|
|
|
| ----------------------------------------------------------------- |
|
32
|
|
|
*/ |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Register the service provider. |
|
36
|
|
|
*/ |
|
37
|
252 |
|
public function register(): void |
|
38
|
|
|
{ |
|
39
|
252 |
|
parent::register(); |
|
40
|
|
|
|
|
41
|
252 |
|
$this->registerConfig(); |
|
42
|
|
|
|
|
43
|
252 |
|
$this->bindModels(); |
|
44
|
252 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Boot the service provider. |
|
48
|
|
|
*/ |
|
49
|
252 |
|
public function boot(): void |
|
50
|
|
|
{ |
|
51
|
252 |
|
if ($this->app->runningInConsole()) { |
|
52
|
252 |
|
$this->publishConfig(); |
|
53
|
|
|
|
|
54
|
252 |
|
Messenger::$runsMigrations |
|
55
|
252 |
|
? $this->loadMigrations() |
|
56
|
|
|
: $this->publishMigrations(); |
|
57
|
|
|
} |
|
58
|
252 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get the services provided by the provider. |
|
62
|
|
|
* |
|
63
|
|
|
* @return array |
|
64
|
|
|
*/ |
|
65
|
6 |
|
public function provides(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
6 |
|
Contracts\Discussion::class, |
|
69
|
|
|
Contracts\Message::class, |
|
70
|
|
|
Contracts\Participation::class, |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/* ----------------------------------------------------------------- |
|
75
|
|
|
| Other Methods |
|
76
|
|
|
| ----------------------------------------------------------------- |
|
77
|
|
|
*/ |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Bind the models. |
|
81
|
|
|
*/ |
|
82
|
252 |
|
private function bindModels(): void |
|
83
|
|
|
{ |
|
84
|
252 |
|
$config = $this->app['config']; |
|
85
|
|
|
$bindings = [ |
|
86
|
252 |
|
Contracts\Discussion::class => 'discussions', |
|
87
|
|
|
Contracts\Message::class => 'messages', |
|
88
|
|
|
Contracts\Participation::class => 'participations', |
|
89
|
|
|
]; |
|
90
|
|
|
|
|
91
|
252 |
|
foreach ($bindings as $contract => $key) { |
|
92
|
252 |
|
$this->bind($contract, $config->get("{$this->package}.{$key}.model")); |
|
93
|
|
|
} |
|
94
|
252 |
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|