|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of GitterBot package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Serafim <[email protected]> |
|
6
|
|
|
* @date 26.01.2016 4:59 |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
namespace App\Console\Commands; |
|
12
|
|
|
|
|
13
|
|
|
use Gitter\Client; |
|
14
|
|
|
use React\EventLoop\Factory; |
|
15
|
|
|
use Illuminate\Console\Command; |
|
16
|
|
|
use React\EventLoop\LoopInterface; |
|
17
|
|
|
use Illuminate\Contracts\Container\Container; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class AbstractCommand |
|
21
|
|
|
* @package App\Console\Commands |
|
22
|
|
|
*/ |
|
23
|
|
|
abstract class AbstractCommand extends Command |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @param Container $container |
|
27
|
|
|
* @param $token |
|
28
|
|
|
* @return Client |
|
29
|
|
|
*/ |
|
30
|
|
|
protected function createClient(Container $container, $token) |
|
31
|
|
|
{ |
|
32
|
|
|
$loop = Factory::create(); |
|
33
|
|
|
$client = new Client($loop, $token); |
|
34
|
|
|
|
|
35
|
|
|
// Bind container |
|
36
|
|
|
$container->singleton(LoopInterface::class, function() use ($loop) { return $loop; }); |
|
37
|
|
|
$container->singleton(Client::class, function() use ($client) { return $client; }); |
|
38
|
|
|
|
|
39
|
|
|
return $client; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param Client $client |
|
44
|
|
|
* @param string $roomId |
|
45
|
|
|
* @param \Closure $fulfilled |
|
46
|
|
|
* @return \React\Promise\PromiseInterface |
|
47
|
|
|
*/ |
|
48
|
|
|
public function findRoom(Client $client, string $roomId, \Closure $fulfilled) |
|
49
|
|
|
{ |
|
50
|
|
|
return $client->getRoomByUri($roomId) |
|
51
|
|
|
->then($fulfilled, function(\Throwable $exception) use ($roomId, $client, $fulfilled) { |
|
|
|
|
|
|
52
|
|
|
$client->getRoomById($roomId)->then($fulfilled, function(\Throwable $exception) { |
|
|
|
|
|
|
53
|
|
|
$this->error(sprintf('Room "%s" not found.', $this->argument('room'))); |
|
54
|
|
|
}); |
|
55
|
|
|
}); |
|
56
|
|
|
} |
|
57
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.