|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace GetStream\StreamLaravel; |
| 4 | + |
| 5 | +use Illuminate\Support\ServiceProvider; |
| 6 | + |
| 7 | +class StreamLumenServiceProvider extends ServiceProvider |
| 8 | +{ |
| 9 | + /** |
| 10 | + * Bootstrap the application events. |
| 11 | + * |
| 12 | + * @return void |
| 13 | + */ |
| 14 | + public function boot() |
| 15 | + { |
| 16 | + if (method_exists($this, 'publishes')) { |
| 17 | + $this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel'); |
| 18 | + |
| 19 | + $this->publishes([ |
| 20 | + __DIR__.'/../../config/config.php' => app()->configure('stream-laravel.php'), |
| 21 | + __DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'), |
| 22 | + ]); |
| 23 | + } else { |
| 24 | + $this->package('get-stream/stream-laravel'); |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + /** |
| 29 | + * Register the service provider. |
| 30 | + * |
| 31 | + * @return void |
| 32 | + */ |
| 33 | + public function register() |
| 34 | + { |
| 35 | + if (method_exists($this, 'publishes')) { |
| 36 | + $this->registerResources(); |
| 37 | + } |
| 38 | + |
| 39 | + $this->app->singleton('feed_manager', function($app) { |
| 40 | + $manager_class = config('stream-laravel.feed_manager_class'); |
| 41 | + $api_key = config('stream-laravel.api_key'); |
| 42 | + $api_secret = config('stream-laravel.api_secret'); |
| 43 | + |
| 44 | + return new $manager_class($api_key, $api_secret, $this->app['config']); |
| 45 | + }); |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Register the package resources. |
| 50 | + * |
| 51 | + * @return void |
| 52 | + */ |
| 53 | + protected function registerResources() |
| 54 | + { |
| 55 | + $userConfigFile = app()->configure('stream-laravel.php'); |
| 56 | + $packageConfigFile = __DIR__.'/../../config/config.php'; |
| 57 | + $config = $this->app['files']->getRequire($packageConfigFile); |
| 58 | + |
| 59 | + if (file_exists($userConfigFile)) { |
| 60 | + $userConfig = $this->app['files']->getRequire($userConfigFile); |
| 61 | + $config = array_replace_recursive($config, $userConfig); |
| 62 | + } |
| 63 | + |
| 64 | + $namespace = 'stream-laravel::'; |
| 65 | + |
| 66 | + foreach($config as $key => $value) { |
| 67 | + $this->app['config']->set($namespace . $key , $value); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments