1
|
|
|
<?php namespace Arcanedev\LaravelDisqus; |
2
|
|
|
|
3
|
|
|
use Arcanedev\Support\PackageServiceProvider; |
4
|
|
|
use Illuminate\Contracts\Http\Kernel; |
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* Class LaravelDisqusServiceProvider |
8
|
|
|
* |
9
|
|
|
* @package Arcanedev\LaravelDisqus |
10
|
|
|
* @author ARCANEDEV <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
class LaravelDisqusServiceProvider extends PackageServiceProvider |
13
|
|
|
{ |
14
|
|
|
/* ----------------------------------------------------------------- |
15
|
|
|
| Properties |
16
|
|
|
| ----------------------------------------------------------------- |
17
|
|
|
*/ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Package name. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $package = 'laravel-disqus'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Indicates if loading of the provider is deferred. |
28
|
|
|
* |
29
|
|
|
* @var bool |
30
|
|
|
*/ |
31
|
|
|
protected $defer = true; |
32
|
|
|
|
33
|
|
|
/* ----------------------------------------------------------------- |
34
|
|
|
| Main Methods |
35
|
|
|
| ----------------------------------------------------------------- |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Register the service provider. |
40
|
|
|
*/ |
41
|
36 |
|
public function register() |
42
|
|
|
{ |
43
|
36 |
|
parent::register(); |
44
|
|
|
|
45
|
36 |
|
$this->registerConfig(); |
46
|
|
|
|
47
|
36 |
|
$this->singleton(Contracts\Disqus::class, function ($app) { |
48
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
49
|
30 |
|
$config = $app['config']; |
50
|
|
|
|
51
|
30 |
|
return tap(new Disqus($config->get('laravel-disqus.options', [])), function (Contracts\Disqus $disqus) use ($config) { |
52
|
30 |
|
$disqus->setEnabled($config->get('laravel-disqus.enabled', false)); |
53
|
30 |
|
}); |
54
|
36 |
|
}); |
55
|
36 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Boot the service provider. |
59
|
|
|
*/ |
60
|
36 |
|
public function boot() |
61
|
|
|
{ |
62
|
36 |
|
parent::boot(); |
63
|
|
|
|
64
|
36 |
|
$this->publishConfig(); |
65
|
36 |
|
$this->publishViews(); |
66
|
|
|
|
67
|
36 |
|
$this->registerMiddleware(); |
68
|
36 |
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get the services provided by the provider. |
72
|
|
|
* |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
6 |
|
public function provides() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
6 |
|
Contracts\Disqus::class, |
79
|
|
|
]; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/* ----------------------------------------------------------------- |
83
|
|
|
| Other Methods |
84
|
|
|
| ----------------------------------------------------------------- |
85
|
|
|
*/ |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Register Disqus Middleware. |
89
|
|
|
*/ |
90
|
36 |
|
private function registerMiddleware() |
91
|
|
|
{ |
92
|
36 |
|
if ($middleware = $this->config()->get('laravel-disqus.middleware')) { |
93
|
36 |
|
$this->app[Kernel::class]->pushMiddleware($middleware); |
94
|
|
|
} |
95
|
36 |
|
} |
96
|
|
|
} |
97
|
|
|
|