forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataSourceServiceProvider.php
More file actions
77 lines (64 loc) · 1.99 KB
/
Copy pathDataSourceServiceProvider.php
File metadata and controls
77 lines (64 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Ushahidi\App\DataSource;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Event;
class DataSourceServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->registerStorage();
$this->registerManager();
$this->registerCommands();
}
public function boot()
{
$this->app->make('datasources')->registerRoutes($this->app->router);
Event::listen('multisite.site.changed', function () {
// Reset datasources
$this->app->make('datasources')->clearResolvedSources();
});
}
/**
* Register the data provider manager.
*
* @return void
*/
protected function registerManager()
{
$this->app->singleton('datasources', function ($app) {
$configRepo = $this->app->make(\Ushahidi\Core\Entity\ConfigRepository::class);
$manager = new DataSourceManager($configRepo);
$manager->setStorage($app->make(DataSourceStorage::class));
return $manager;
});
$this->app->singleton(DataSourceManager::class, function ($app) {
return $app->make('datasources');
});
}
protected function registerStorage()
{
$this->app->singleton(DataSourceStorage::class, function ($app) {
return $this->makeStorage();
});
}
protected function makeStorage()
{
$receiveUsecase = $this->app->make(\Ushahidi\Factory\UsecaseFactory::class)
->get('messages', 'receive');
$messageRepo = $this->app->make(\Ushahidi\Core\Entity\MessageRepository::class);
return new DataSourceStorage($receiveUsecase, $messageRepo);
}
public function registerCommands()
{
$this->commands([
Console\IncomingCommand::class,
Console\OutgoingCommand::class,
Console\ListCommand::class,
]);
}
}