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

FeedServiceProvider::getFeeds()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
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