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