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
|
|
|
* Package name. |
20
|
|
|
* |
21
|
|
|
* @var string |
22
|
|
|
*/ |
23
|
|
|
protected $package = 'laravel-disqus'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Indicates if loading of the provider is deferred. |
27
|
|
|
* |
28
|
|
|
* @var bool |
29
|
|
|
*/ |
30
|
|
|
protected $defer = true; |
31
|
|
|
|
32
|
|
|
/* ------------------------------------------------------------------------------------------------ |
33
|
|
|
| Getters & Setters |
34
|
|
|
| ------------------------------------------------------------------------------------------------ |
35
|
|
|
*/ |
36
|
|
|
/** |
37
|
|
|
* Get the base path of the package. |
38
|
|
|
* |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
36 |
|
public function getBasePath() |
42
|
|
|
{ |
43
|
36 |
|
return dirname(__DIR__); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/* ------------------------------------------------------------------------------------------------ |
47
|
|
|
| Main Functions |
48
|
|
|
| ------------------------------------------------------------------------------------------------ |
49
|
|
|
*/ |
50
|
|
|
/** |
51
|
|
|
* Register the service provider. |
52
|
|
|
*/ |
53
|
36 |
|
public function register() |
54
|
|
|
{ |
55
|
36 |
|
$this->registerConfig(); |
56
|
|
|
|
57
|
36 |
|
$this->singleton(Contracts\Disqus::class, function ($app) { |
58
|
|
|
/** @var \Illuminate\Contracts\Config\Repository $config */ |
59
|
30 |
|
$config = $app['config']; |
60
|
30 |
|
$disqus = new Disqus($config->get('laravel-disqus.options', [])); |
61
|
|
|
|
62
|
30 |
|
$disqus->setEnabled($config->get('laravel-disqus.enabled', false)); |
63
|
|
|
|
64
|
30 |
|
return $disqus; |
65
|
36 |
|
}); |
66
|
36 |
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Boot the service provider. |
70
|
|
|
*/ |
71
|
36 |
|
public function boot() |
72
|
|
|
{ |
73
|
36 |
|
$this->publishConfig(); |
74
|
36 |
|
$this->publishViews(); |
75
|
|
|
|
76
|
36 |
|
$this->registerMiddleware(); |
77
|
36 |
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Get the services provided by the provider. |
81
|
|
|
* |
82
|
|
|
* @return array |
83
|
|
|
*/ |
84
|
15 |
|
public function provides() |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
15 |
|
Contracts\Disqus::class, |
88
|
5 |
|
]; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/* ------------------------------------------------------------------------------------------------ |
92
|
|
|
| Other Functions |
93
|
|
|
| ------------------------------------------------------------------------------------------------ |
94
|
|
|
*/ |
95
|
|
|
/** |
96
|
|
|
* Register Disqus Middleware. |
97
|
|
|
*/ |
98
|
36 |
|
private function registerMiddleware() |
99
|
|
|
{ |
100
|
36 |
|
if ($middleware = $this->config()->get('laravel-disqus.middleware')) { |
101
|
36 |
|
$this->app[Kernel::class]->pushMiddleware($middleware); |
102
|
12 |
|
} |
103
|
36 |
|
} |
104
|
|
|
} |
105
|
|
|
|