1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Laratrade\GDAX\WebSocket\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Config\Repository as RepositoryContract; |
6
|
|
|
use Illuminate\Console\Command; |
7
|
|
|
use Laratrade\GDAX\WebSocket\Contracts\Subscriber as SubscriberContract; |
8
|
|
|
use Ratchet\Client\Connector; |
9
|
|
|
|
10
|
|
|
class ProcessCommand extends Command |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* The name and signature of the console command. |
14
|
|
|
* |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected $signature = 'gdax:websocket:process'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The console command description. |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $description = 'Process the WebSocket data'; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* The connector instance. |
28
|
|
|
* |
29
|
|
|
* @var Connector |
30
|
|
|
*/ |
31
|
|
|
protected $connector; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The config repository instance. |
35
|
|
|
* |
36
|
|
|
* @var RepositoryContract |
37
|
|
|
*/ |
38
|
|
|
protected $config; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The subscriber instance. |
42
|
|
|
* |
43
|
|
|
* @var SubscriberContract |
44
|
|
|
*/ |
45
|
|
|
protected $subscriber; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Create a new command instance. |
49
|
|
|
* |
50
|
|
|
* @param Connector $connector |
51
|
|
|
* @param RepositoryContract $config |
52
|
|
|
* @param SubscriberContract $subscriber |
53
|
|
|
*/ |
54
|
4 |
|
public function __construct(Connector $connector, RepositoryContract $config, SubscriberContract $subscriber) |
55
|
|
|
{ |
56
|
4 |
|
parent::__construct(); |
57
|
|
|
|
58
|
4 |
|
$this->connector = $connector; |
59
|
4 |
|
$this->config = $config; |
60
|
4 |
|
$this->subscriber = $subscriber; |
61
|
4 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Execute the console command. |
65
|
|
|
* |
66
|
|
|
* @return void |
67
|
|
|
*/ |
68
|
2 |
|
public function handle(): void |
69
|
|
|
{ |
70
|
2 |
|
$connector = $this->connector; |
71
|
2 |
|
$connection = $connector($this->config->get('websocket.url')); |
72
|
|
|
|
73
|
2 |
|
$this->subscriber->subscribe($connection); |
74
|
2 |
|
} |
75
|
|
|
} |
76
|
|
|
|