1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* |
5
|
|
|
* @author Donii Sergii <[email protected]> |
6
|
|
|
* Date: 10/24/17 |
7
|
|
|
* Time: 10:33 AM |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace sonrac\WAMP\Commands; |
11
|
|
|
|
12
|
|
|
use Illuminate\Console\Command; |
13
|
|
|
use sonrac\WAMP\Exceptions\InvalidWampTransportProvider; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Class RunServer |
17
|
|
|
* Run WAMP server command |
18
|
|
|
* |
19
|
|
|
* @package sonrac\WAMP\Commands |
20
|
|
|
*/ |
21
|
|
|
class RunServer extends Command |
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* WAMP router host |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $host = '127.0.0.1'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Wamp realm to used |
32
|
|
|
* |
33
|
|
|
* @var string |
34
|
|
|
*/ |
35
|
|
|
protected $realm; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Providers list |
39
|
|
|
* |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
protected $providers = []; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* WAMP router port |
46
|
|
|
* |
47
|
|
|
* @var int |
48
|
|
|
*/ |
49
|
|
|
protected $port = '9090'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Run in debug mode. If `in-background` option is disable, logging to storage_path('server-{pid}.log') |
53
|
|
|
* |
54
|
|
|
* @var bool |
55
|
|
|
*/ |
56
|
|
|
protected $noDebug = false; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Run in loop or once |
60
|
|
|
* |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
protected $runOnce = false; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Specify the router protocol as wss |
67
|
|
|
* |
68
|
|
|
* @var bool |
69
|
|
|
*/ |
70
|
|
|
protected $tls = false; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var null|string |
74
|
|
|
*/ |
75
|
|
|
protected $path = null; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Transport provider class |
79
|
|
|
* |
80
|
|
|
* @var string|\Thruway\Transport\RatchetTransportProvider|null |
81
|
|
|
* |
82
|
|
|
* @author Donii Sergii <[email protected]> |
83
|
|
|
*/ |
84
|
|
|
protected $transportProvider = 'Thruway\Transport\RatchetTransportProvider'; |
85
|
|
|
|
86
|
|
|
protected $name = 'run:wamp-server {--realm=?} {--host=?} {--port=?} {--tls?} {--path=?} {--providers=*?} {--transportProvider} |
87
|
|
|
{--no-loop?} {--debug?}'; |
88
|
|
|
protected $signature = 'run:wamp-server |
89
|
|
|
{--realm= : Specify WAMP realm to be used} |
90
|
|
|
{--host= : Specify the router host} |
91
|
|
|
{--port= : Specify the router port} |
92
|
|
|
{--tls : Specify the router protocol as wss} |
93
|
|
|
{--path= : Specify the router path component} |
94
|
|
|
{--providers=* : Register provider classes}, |
95
|
|
|
{--no-debug : Disable debug mode.} |
96
|
|
|
{--no-loop : Disable loop runner} |
97
|
|
|
{--transportProvider : Transport provider class} |
98
|
|
|
'; |
99
|
|
|
protected $description = 'Run wamp server'; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Wamp server |
103
|
|
|
* |
104
|
|
|
* @var null|\sonrac\WAMP\Routers\Router |
105
|
|
|
*/ |
106
|
|
|
protected $WAMPServer = null; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Run server handle |
110
|
|
|
* |
111
|
|
|
* @throws \Exception |
112
|
|
|
*/ |
113
|
|
|
public function handle() |
114
|
|
|
{ |
115
|
|
|
$this->parseOptions(); |
116
|
|
|
|
117
|
|
|
$this->WAMPServer = app()->wampRouter; |
118
|
|
|
$transportProvider = $this->getTransportProvider(); |
119
|
|
|
|
120
|
|
|
$this->WAMPServer->addTransportProvider($transportProvider); |
121
|
|
|
|
122
|
|
|
$this->WAMPServer->start(!$this->runOnce); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Merge config & input options |
127
|
|
|
*/ |
128
|
|
|
protected function parseOptions() |
129
|
|
|
{ |
130
|
|
|
$this->host = $this->getOptionFromInput('host') ?? $this->getConfig('host', $this->host); |
|
|
|
|
131
|
|
|
$this->port = $this->getOptionFromInput('port') ?? $this->getConfig('port', $this->port); |
|
|
|
|
132
|
|
|
$this->path = $this->getOptionFromInput('path') ?? $this->getConfig('path', $this->path); |
|
|
|
|
133
|
|
|
$this->realm = $this->getOptionFromInput('realm') ?? $this->getConfig('realm', $this->realm); |
|
|
|
|
134
|
|
|
$this->providers = $this->getOptionFromInput('providers') ?? $this->getConfig('providers', $this->providers); |
|
|
|
|
135
|
|
|
$this->tls = $this->getOptionFromInput('tls') ?? $this->getConfig('tls', $this->tls); |
136
|
|
|
$this->transportProvider = $this->getOptionFromInput('transportProvider') ?? $this->getConfig('transportProvider', |
|
|
|
|
137
|
|
|
$this->transportProvider); |
138
|
|
|
|
139
|
|
|
$this->noDebug = $this->getOptionFromInput('no-debug') ?? $this->noDebug; |
|
|
|
|
140
|
|
|
$this->runOnce = $this->getOptionFromInput('no-loop') ?? $this->runOnce; |
|
|
|
|
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Get WAMP server transport provider |
145
|
|
|
* |
146
|
|
|
* @return null|string|\Thruway\Transport\RatchetTransportProvider |
147
|
|
|
* |
148
|
|
|
* @throws InvalidWampTransportProvider |
149
|
|
|
* |
150
|
|
|
* @author Donii Sergii <[email protected]> |
151
|
|
|
*/ |
152
|
|
|
protected function getTransportProvider() |
153
|
|
|
{ |
154
|
|
|
if (is_object($this->transportProvider)) { |
155
|
|
|
return $this->transportProvider; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
if (is_null($this->transportProvider) || empty($this->transportProvider)) { |
159
|
|
|
$this->transportProvider = 'Thruway\Transport\RatchetTransportProvider'; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
if (is_string($this->transportProvider)) { |
163
|
|
|
return $this->transportProvider = new $this->transportProvider($this->host, $this->port); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
throw new InvalidWampTransportProvider(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* Get option value from input |
171
|
|
|
* |
172
|
|
|
* @param string $optionName |
173
|
|
|
* |
174
|
|
|
* @return array|null|string |
175
|
|
|
*/ |
176
|
|
|
protected function getOptionFromInput(string $optionName, $default = null) |
177
|
|
|
{ |
178
|
|
|
if (null === $this->input->getOption($optionName)) { |
179
|
|
|
return $default; |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return $this->option($optionName); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Get minion config |
187
|
|
|
* |
188
|
|
|
* @param string|null $optName Option name |
189
|
|
|
* @param mixed $default Default value |
190
|
|
|
* |
191
|
|
|
* @return array|string|int|null |
192
|
|
|
*/ |
193
|
|
|
protected function getConfig($optName = null, $default = null) |
194
|
|
|
{ |
195
|
|
|
$options = config('minion') ?? []; |
196
|
|
|
|
197
|
|
|
if (null === $optName) { |
198
|
|
|
return $options ?? []; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
return isset($options[$optName]) ? $options[$optName] : $default; |
202
|
|
|
} |
203
|
|
|
} |
204
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.