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 class($loop, $token) extends Client { |
34
|
|
|
/** |
35
|
|
|
* @var bool |
36
|
|
|
*/ |
37
|
|
|
protected $fallbackMode = true; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param bool $value |
41
|
|
|
* @return $this |
42
|
|
|
*/ |
43
|
|
|
public function setFallbackMode(bool $value = true) |
44
|
|
|
{ |
45
|
|
|
$this->fallbackMode = $value; |
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return bool |
51
|
|
|
*/ |
52
|
|
|
public function isFallbackMode() |
53
|
|
|
{ |
54
|
|
|
return $this->fallbackMode; |
55
|
|
|
} |
56
|
|
|
}; |
57
|
|
|
|
58
|
|
|
// Bind container |
59
|
|
|
$container->instance(LoopInterface::class, $loop); |
60
|
|
|
$container->instance(Client::class, $client); |
61
|
|
|
|
62
|
|
|
return $client; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @param Client $client |
67
|
|
|
* @param string $roomId |
68
|
|
|
* @param \Closure $fulfilled |
69
|
|
|
* @return \React\Promise\PromiseInterface |
70
|
|
|
*/ |
71
|
|
|
public function findRoom(Client $client, string $roomId, \Closure $fulfilled) |
72
|
|
|
{ |
73
|
|
|
return $client->getRoomByUri($roomId) |
74
|
|
|
->then($fulfilled, function(\Throwable $exception) use ($roomId, $client, $fulfilled) { |
|
|
|
|
75
|
|
|
$client->getRoomById($roomId)->then($fulfilled, function(\Throwable $exception) { |
|
|
|
|
76
|
|
|
$this->error(sprintf('Room "%s" not found.', $this->argument('room'))); |
77
|
|
|
}); |
78
|
|
|
}); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.