1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\Feed; |
4
|
|
|
|
5
|
|
|
use Spatie\Feed\Helpers\Path; |
6
|
|
|
use Illuminate\Support\Facades\View; |
7
|
|
|
use Spatie\Feed\Http\FeedController; |
8
|
|
|
use Illuminate\Support\ServiceProvider; |
9
|
|
|
|
10
|
|
|
class FeedServiceProvider extends ServiceProvider |
11
|
|
|
{ |
12
|
|
|
public function boot() |
13
|
|
|
{ |
14
|
|
|
$this->publishes([ |
15
|
|
|
__DIR__.'/../config/feed.php' => config_path('feed.php'), |
16
|
|
|
], 'config'); |
17
|
|
|
|
18
|
|
|
$this->loadViewsFrom(__DIR__.'/../resources/views', 'feed'); |
19
|
|
|
|
20
|
|
|
$this->publishes([ |
21
|
|
|
__DIR__.'/../resources/views' => resource_path('views/vendor/feed'), |
22
|
|
|
], 'views'); |
23
|
|
|
|
24
|
|
|
$this->registerLinksComposer(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function register() |
28
|
|
|
{ |
29
|
|
|
$this->mergeConfigFrom(__DIR__.'/../config/feed.php', 'feed'); |
30
|
|
|
|
31
|
|
|
$this->registerRouteMacro(); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
protected function registerRouteMacro() |
35
|
|
|
{ |
36
|
|
|
$router = $this->app['router']; |
37
|
|
|
|
38
|
|
|
$router->macro('feeds', function ($baseUrl = '') use ($router) { |
39
|
|
|
foreach (config('feed.feeds') as $name => $configuration) { |
40
|
|
|
$url = Path::merge($baseUrl, $configuration['url']); |
41
|
|
|
|
42
|
|
|
$router->get($url, '\\'.FeedController::class)->name("feeds.{$name}"); |
43
|
|
|
} |
44
|
|
|
}); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function registerLinksComposer() |
48
|
|
|
{ |
49
|
|
|
View::composer('feed::links', function ($view) { |
50
|
|
|
$view->with('feeds', $this->feeds()); |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
protected function feeds() |
55
|
|
|
{ |
56
|
|
|
return collect(config('feed.feeds'))->mapWithKeys(function ($feed, $name) { |
57
|
|
|
return [$name => $feed['title']]; |
58
|
|
|
}); |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|