|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace ElfSundae\BearyChat\Laravel; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
use Illuminate\Support\ServiceProvider as LaravelServiceProvider; |
|
7
|
|
|
|
|
8
|
|
|
class ServiceProvider extends LaravelServiceProvider |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* Indicates if loading of the provider is deferred. |
|
12
|
|
|
* |
|
13
|
|
|
* @var bool |
|
14
|
|
|
*/ |
|
15
|
|
|
protected $defer = false; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Indicates if the application is Laravel 4. |
|
19
|
|
|
* |
|
20
|
|
|
* @var bool |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $isLaravel4 = false; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Indicates if the application is Laravel 5. |
|
26
|
|
|
* |
|
27
|
|
|
* @var bool |
|
28
|
|
|
*/ |
|
29
|
|
|
protected $isLaravel5 = false; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Indicates if the application is Lumen. |
|
33
|
|
|
* |
|
34
|
|
|
* @var bool |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $isLumen = false; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Create a new service provider instance. |
|
40
|
|
|
* |
|
41
|
|
|
* @param \Illuminate\Contracts\Foundation\Application $app |
|
42
|
|
|
*/ |
|
43
|
5 |
|
public function __construct($app) |
|
44
|
|
|
{ |
|
45
|
5 |
|
parent::__construct($app); |
|
46
|
|
|
|
|
47
|
5 |
|
$appVersion = method_exists($app, 'version') ? $app->version() : $app::VERSION; |
|
48
|
|
|
|
|
49
|
5 |
|
$this->isLaravel4 = (int) $appVersion == 4; |
|
50
|
5 |
|
$this->isLaravel5 = (int) $appVersion == 5; |
|
51
|
5 |
|
$this->isLumen = Str::contains($appVersion, 'Lumen'); |
|
52
|
5 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Bootstrap any application services. |
|
56
|
|
|
* |
|
57
|
|
|
* @return void |
|
58
|
|
|
*/ |
|
59
|
5 |
|
public function boot() |
|
60
|
|
|
{ |
|
61
|
5 |
|
if ($this->isLaravel4) { |
|
62
|
|
|
$this->package('elfsundae/laravel-bearychat', 'bearychat', __DIR__); |
|
|
|
|
|
|
63
|
|
|
} else { |
|
64
|
5 |
|
$this->publishes([ |
|
65
|
5 |
|
$this->getConfigFromPath() => $this->getConfigToPath(), |
|
66
|
5 |
|
], 'laravel-bearychat'); |
|
67
|
|
|
} |
|
68
|
5 |
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Register the service provider. |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
5 |
|
public function register() |
|
76
|
|
|
{ |
|
77
|
5 |
|
if (! $this->isLaravel4) { |
|
78
|
5 |
|
$this->mergeConfigFrom($this->getConfigFromPath(), 'bearychat'); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
5 |
|
$this->app->singleton('bearychat', function ($app) { |
|
82
|
5 |
|
return (new ClientManager($app)) |
|
83
|
5 |
|
->setDefaultName($this->getConfig('default')) |
|
84
|
5 |
|
->setClientsDefaults($this->getConfig('clients_defaults')) |
|
85
|
5 |
|
->setClientsConfig($this->getConfig('clients')); |
|
86
|
5 |
|
}); |
|
87
|
|
|
|
|
88
|
5 |
|
$this->app->alias('bearychat', ClientManager::class); |
|
89
|
|
|
|
|
90
|
5 |
|
$this->aliasFacades(); |
|
91
|
5 |
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Get the source config path. |
|
95
|
|
|
* |
|
96
|
|
|
* @return string |
|
97
|
|
|
*/ |
|
98
|
5 |
|
protected function getConfigFromPath() |
|
99
|
|
|
{ |
|
100
|
5 |
|
return __DIR__.'/config/config.php'; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get the config destination path. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
5 |
|
protected function getConfigToPath() |
|
109
|
|
|
{ |
|
110
|
5 |
|
return $this->isLumen ? base_path('config/bearychat.php') : config_path('bearychat.php'); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* Register facade alias. |
|
115
|
|
|
* |
|
116
|
|
|
* @return void |
|
117
|
|
|
*/ |
|
118
|
5 |
|
protected function aliasFacades() |
|
119
|
|
|
{ |
|
120
|
5 |
|
if (class_exists('Illuminate\Foundation\AliasLoader')) { |
|
121
|
5 |
|
\Illuminate\Foundation\AliasLoader::getInstance()->alias('BearyChat', Facade::class); |
|
122
|
|
|
} else { |
|
123
|
|
|
class_alias(Facade::class, 'BearyChat'); |
|
124
|
|
|
} |
|
125
|
5 |
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Get the bearychat configuration. |
|
129
|
|
|
* |
|
130
|
|
|
* @param string $key |
|
131
|
|
|
* @param mixed $default |
|
132
|
|
|
* @return mixed |
|
133
|
|
|
*/ |
|
134
|
5 |
|
protected function getConfig($key, $default = null) |
|
135
|
|
|
{ |
|
136
|
5 |
|
$prefix = 'bearychat'.($this->isLaravel4 ? '::' : '.'); |
|
137
|
|
|
|
|
138
|
5 |
|
return $this->app['config']->get($prefix.$key, $default); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get the services provided by the provider. |
|
143
|
|
|
* |
|
144
|
|
|
* @return string[] |
|
145
|
|
|
*/ |
|
146
|
|
|
public function provides() |
|
147
|
|
|
{ |
|
148
|
|
|
return ['bearychat']; |
|
149
|
|
|
} |
|
150
|
|
|
} |
|
151
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.