Completed
Pull Request — master (#3)
by ARCANEDEV
23:38
created

LaravelDisqusServiceProvider::getBasePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
ccs 2
cts 2
cp 1
crap 1
rs 10
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 144
    public function register()
42
    {
43 144
        parent::register();
44
45
        $this->registerConfig();
46
47
        $this->singleton(Contracts\Disqus::class, function ($app) {
48
            /** @var  \Illuminate\Contracts\Config\Repository  $config */
49
            $config = $app['config'];
50
            $disqus = new Disqus($config->get('laravel-disqus.options', []));
51
52
            $disqus->setEnabled($config->get('laravel-disqus.enabled', false));
53 144
54
            return $disqus;
55 144
        });
56
    }
57 144
58
    /**
59 120
     * Boot the service provider.
60 120
     */
61
    public function boot()
62 120
    {
63
        parent::boot();
64 120
65 144
        $this->publishConfig();
66 144
        $this->publishViews();
67
68
        $this->registerMiddleware();
69
    }
70
71 144
    /**
72
     * Get the services provided by the provider.
73 144
     *
74 144
     * @return array
75
     */
76 144
    public function provides()
77 144
    {
78
        return [
79
            Contracts\Disqus::class,
80
        ];
81
    }
82
83
    /* -----------------------------------------------------------------
84 24
     |  Other Methods
85
     | -----------------------------------------------------------------
86
     */
87 24
88 8
    /**
89
     * Register Disqus Middleware.
90
     */
91
    private function registerMiddleware()
92
    {
93
        if ($middleware = $this->config()->get('laravel-disqus.middleware')) {
94
            $this->app[Kernel::class]->pushMiddleware($middleware);
95
        }
96
    }
97
}
98