1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of GitterBot package. |
4
|
|
|
* |
5
|
|
|
* @author Serafim <[email protected]> |
6
|
|
|
* @author butschster <[email protected]> |
7
|
|
|
* @date 09.04.2016 3:09 |
8
|
|
|
* |
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
10
|
|
|
* file that was distributed with this source code. |
11
|
|
|
*/ |
12
|
|
|
namespace Core\Providers; |
13
|
|
|
|
14
|
|
|
use Domains\BotManager; |
15
|
|
|
use Domains\RoomManager; |
16
|
|
|
use Gitter\Client; |
17
|
|
|
use Illuminate\Container\Container; |
18
|
|
|
use Illuminate\Support\ServiceProvider; |
19
|
|
|
use Interfaces\Gitter\StandartGitterRoom; |
20
|
|
|
use Interfaces\Slack\StandartSlackRoom; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Class GitterClientServiceProvider |
24
|
|
|
* @package Core\Providers |
25
|
|
|
*/ |
26
|
|
|
class GitterClientServiceProvider extends ServiceProvider |
27
|
|
|
{ |
28
|
|
|
|
29
|
|
|
public function register() |
30
|
|
|
{ |
31
|
|
|
$this->app->singleton(Client::class, function (Container $app) { |
32
|
|
|
return new Client($app['config']->get('gitter.token')); |
33
|
|
|
}); |
34
|
|
|
|
35
|
|
|
$this->app->singleton('bot', function (Container $app) { |
36
|
|
|
/** @var Client $client */ |
37
|
|
|
$client = $app->make(Client::class); |
38
|
|
|
return $client->http->getCurrentUser()->wait(); |
39
|
|
|
}); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function boot() |
43
|
|
|
{ |
44
|
|
|
$this->app->singleton('bot.manager', function (Container $app) { |
45
|
|
|
return new BotManager($app); |
|
|
|
|
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
$this->app->singleton('room.manager', function (Container $app) { |
|
|
|
|
49
|
|
|
$manager = new RoomManager(); |
50
|
|
|
|
51
|
|
|
$this->registerGitterRooms($manager); |
52
|
|
|
$this->registerSlackRooms($manager); |
53
|
|
|
|
54
|
|
|
return $manager; |
55
|
|
|
}); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function registerGitterRooms(RoomManager $manager) |
59
|
|
|
{ |
60
|
|
|
foreach ((array) $this->app['config']->get('gitter.rooms') as $room => $groups) { |
61
|
|
|
$manager->register( |
62
|
|
|
new StandartGitterRoom($room, $groups, \Config::get('gitter.middlewares')) |
63
|
|
|
); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function registerSlackRooms(RoomManager $manager) |
68
|
|
|
{ |
69
|
|
|
foreach ((array) $this->app['config']->get('slack.rooms') as $roomId => $groups) { |
70
|
|
|
$manager->register( |
71
|
|
|
new StandartSlackRoom($roomId, $groups, \Config::get('slack.middlewares')) |
72
|
|
|
); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
} |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.