LaravelRSSFeedServiceProvider::getConfigPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace ejdelmonico\LaravelRSSFeed;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class LaravelRSSFeedServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Indicates if loading of the provider is deferred.
11
     *
12
     * @var bool
13
     */
14
    protected $defer = true;
15
16
    /**
17
     * Bootstrap the package events.
18
     */
19
    public function boot()
20
    {
21
        $configPath = __DIR__.'/../config/feed.php';
22
23
        $this->publishes(
24
            [
25
                $configPath => $this->getConfigPath(),
26
            ],
27
            'config'
28
        );
29
    }
30
31
    /**
32
     * Register the service provider.
33
     */
34
    public function register()
35
    {
36
        $configPath = __DIR__.'/../config/feed.php';
37
        $this->mergeConfigFrom($configPath, 'feed');
38
39
        $this->app->singleton(
40
            'feed',
41
            function () {
42
                $config = config('feed');
43
44
                if (!$config) {
45
                    throw new \RuntimeException(
46
                        'Configuration not available. Run `php artisan vendor:publish '
47
                        .'--provider="ejdelmonico\LaravelRSSFeed\LaravelRSSFeedServiceProvider" --tag=config`'
48
                    );
49
                }
50
51
                return new FeedFactory($config);
52
            }
53
        );
54
55
        $this->app->alias('feed', FeedFactory::class);
56
    }
57
58
    /**
59
     * Get the services from provider.
60
     *
61
     * @return array
62
     */
63
    public function provides()
64
    {
65
        return ['feed'];
66
    }
67
68
    /**
69
     * Get the config path.
70
     *
71
     * @return string
72
     */
73
    protected function getConfigPath()
74
    {
75
        return config_path('feed.php');
76
    }
77
}
78