Completed
Push — master ( a7511e...809eb4 )
by Jolita
02:07
created

FeedServiceProvider   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 5
c 3
b 0
f 0
lcom 1
cbo 3
dl 0
loc 48
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 10 1
A register() 0 6 1
A registerFeeds() 0 9 2
A registerRoute() 0 8 1
1
<?php
2
3
namespace Spatie\Feed;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class FeedServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     */
12
    public function boot()
13
    {
14
        $this->publishes([
15
            __DIR__.'/../config/laravel-feed.php' => config_path('laravel-feed.php'),
16
        ], 'config');
17
18
        $this->loadViewsFrom(__DIR__.'/../resources/views', 'laravel-feed');
19
20
        $this->registerFeeds();
21
    }
22
23
    /**
24
     * Register the application services.
25
     */
26
    public function register()
27
    {
28
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-feed.php', 'laravel-feed');
29
30
        $this->app->singleton(Feed::class);
31
    }
32
33
    /**
34
     * Gets feeds routes and generates feeds.
35
     */
36
    protected function registerFeeds()
37
    {
38
        collect(config('laravel-feed.feeds'))->each(function ($feedConfiguration) {
39
            if (!$feedConfiguration['url']) {
40
                return;
41
            }
42
            $this->registerRoute($feedConfiguration);
43
        });
44
    }
45
46
    protected function registerRoute($feedConfiguration)
47
    {
48
        $this->app['router']->get($feedConfiguration['url'], function () use ($feedConfiguration) {
49
50
            return $this->app->make(Feed::class)->getFeedResponse($feedConfiguration);
51
52
        });
53
    }
54
}
55