Skip to content

Commit e018559

Browse files
support old config
1 parent 12605ce commit e018559

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

src/GetStream/StreamLaravel/StreamLaravelManager.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@
55
class StreamLaravelManager {
66

77
public $client;
8+
private $config;
89

910
public function __construct($api_key, $api_secret, $config)
1011
{
12+
$this->config = $config;
1113
if (getenv('STREAM_URL') !== false) {
1214
$this->client = Client::herokuConnect(getenv('STREAM_URL'));
1315
} else {
14-
$this->client = new Client($api_key, $api_secret, 'v1.0', '', 10);
15-
$location = config("stream-laravel.location");
16+
$this->client = new Client($api_key, $api_secret);
17+
$location = $this->config->get("stream-laravel::location");
1618
$this->client->setLocation($location);
1719
}
18-
$this->userFeed = config("stream-laravel.user_feed");
20+
$this->userFeed = $this->config->get("stream-laravel::user_feed");
1921
}
2022

2123
public function getUserFeed($user_id)
@@ -25,14 +27,14 @@ public function getUserFeed($user_id)
2527

2628
public function getNotificationFeed($user_id)
2729
{
28-
$user_feed = config("stream-laravel.notification_feed");
30+
$user_feed = $this->config->get("stream-laravel::notification_feed");
2931
return $this->client->feed($user_feed, $user_id);
3032
}
3133

3234
public function getNewsFeeds($user_id)
3335
{
3436
$feeds = array();
35-
$news_feeds = config("stream-laravel.news_feeds");
37+
$news_feeds = $this->config->get("stream-laravel::news_feeds");
3638
foreach ($news_feeds as $feed) {
3739
$feeds[$feed] = $this->client->feed($feed, $user_id);
3840
}
@@ -76,4 +78,4 @@ public function activityDeleted($instance)
7678
$feed->removeActivity($foreignId, true);
7779
}
7880

79-
}
81+
}

src/GetStream/StreamLaravel/StreamLaravelServiceProvider.php

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function boot()
2323
$this->loadViewsFrom(__DIR__.'/../../views', 'stream-laravel');
2424

2525
$this->publishes([
26-
__DIR__.'/../../config/config.php' => config_path('getstream.php'),
26+
__DIR__.'/../../config/config.php' => config_path('stream-laravel.php'),
2727
__DIR__.'/../../views' => base_path('resources/views/vendor/stream-laravel'),
2828
]);
2929
}
@@ -35,21 +35,43 @@ public function boot()
3535
*/
3636
public function register()
3737
{
38-
$this->mergeConfigFrom(
39-
__DIR__.'/../../config/config.php', 'stream-laravel'
40-
);
38+
39+
$this->registerResources();
4140

4241
$this->app['feed_manager'] = $this->app->share(function($app)
4342
{
4443

45-
$manager_class = config('stream-laravel.feed_manager_class');
46-
$api_key = config('stream-laravel.api_key');
47-
$api_secret = config('stream-laravel.api_secret');
44+
$manager_class = $app['config']->get('stream-laravel::feed_manager_class');
45+
$api_key = $app['config']->get('stream-laravel::api_key');
46+
$api_secret = $app['config']->get('stream-laravel::api_secret');
4847

49-
return new $manager_class($api_key, $api_secret, $app['config']);
48+
return new $manager_class($api_key, $api_secret, $this->app['config']);
5049
});
5150
}
5251

52+
/**
53+
* Register the package resources.
54+
*
55+
* @return void
56+
*/
57+
protected function registerResources()
58+
{
59+
$userConfigFile = app()->configPath().'/stream-laravel.php';
60+
$packageConfigFile = __DIR__.'/../../config/config.php';
61+
$config = $this->app['files']->getRequire($packageConfigFile);
62+
63+
if (file_exists($userConfigFile)) {
64+
$userConfig = $this->app['files']->getRequire($userConfigFile);
65+
$config = array_replace_recursive($config, $userConfig);
66+
}
67+
68+
$namespace = 'stream-laravel::';
69+
70+
foreach($config as $key => $value) {
71+
$this->app['config']->set($namespace . $key , $value);
72+
}
73+
}
74+
5375
/**
5476
* Get the services provided by the provider.
5577
*

0 commit comments

Comments
 (0)