1 | <?php |
||
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() |
||
67 | |||
68 | /** |
||
69 | * Get the config path. |
||
70 | * |
||
71 | * @return string |
||
72 | */ |
||
73 | protected function getConfigPath() |
||
77 | } |
||
78 |