|
1
|
|
|
<?php namespace Modules\Setting\Providers; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Foundation\AliasLoader; |
|
4
|
|
|
use Illuminate\Support\ServiceProvider; |
|
5
|
|
|
use Modules\Setting\Entities\Setting; |
|
6
|
|
|
use Modules\Setting\Facades\Settings as SettingsFacade; |
|
7
|
|
|
use Modules\Setting\Repositories\Cache\CacheSettingDecorator; |
|
8
|
|
|
use Modules\Setting\Repositories\Eloquent\EloquentSettingRepository; |
|
9
|
|
|
use Modules\Setting\Repositories\SettingRepository; |
|
10
|
|
|
use Modules\Setting\Support\Settings; |
|
11
|
|
|
|
|
12
|
|
|
class SettingServiceProvider extends ServiceProvider |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Indicates if loading of the provider is deferred. |
|
16
|
|
|
* |
|
17
|
|
|
* @var bool |
|
18
|
|
|
*/ |
|
19
|
|
|
protected $defer = false; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Register the service provider. |
|
23
|
|
|
* |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
public function register() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->registerBindings(); |
|
29
|
|
|
|
|
30
|
|
|
$this->app['setting.settings'] = $this->app->share(function ($app) { |
|
31
|
|
|
return new Settings($app[SettingRepository::class]); |
|
32
|
|
|
}); |
|
33
|
|
|
|
|
34
|
|
|
$this->app->booting(function () { |
|
35
|
|
|
$loader = AliasLoader::getInstance(); |
|
36
|
|
|
$loader->alias('Settings', SettingsFacade::class); |
|
37
|
|
|
}); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Get the services provided by the provider. |
|
42
|
|
|
* |
|
43
|
|
|
* @return array |
|
44
|
|
|
*/ |
|
45
|
|
|
public function provides() |
|
46
|
|
|
{ |
|
47
|
|
|
return array(); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
private function registerBindings() |
|
51
|
|
|
{ |
|
52
|
|
|
$this->app->bind(SettingRepository::class, function () { |
|
53
|
|
|
$repository = new EloquentSettingRepository(new Setting()); |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
if (! config('app.cache')) { |
|
56
|
|
|
return $repository; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
return new CacheSettingDecorator($repository); |
|
60
|
|
|
}); |
|
61
|
|
|
$this->app->bind( |
|
62
|
|
|
\Modules\Core\Contracts\Setting::class, |
|
63
|
|
|
Settings::class |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: