1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: conci |
5
|
|
|
* Date: 10/24/17 |
6
|
|
|
* Time: 10:33 AM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace sonrac\WAMP\Commands; |
10
|
|
|
|
11
|
|
|
use Illuminate\Console\Command; |
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
13
|
|
|
use Thruway\Transport\RatchetTransportProvider; |
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 command in background |
60
|
|
|
* |
61
|
|
|
* @var bool |
62
|
|
|
*/ |
63
|
|
|
protected $noInBackground = false; |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Run in loop or once |
67
|
|
|
* |
68
|
|
|
* @var bool |
69
|
|
|
*/ |
70
|
|
|
protected $runOnce = false; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Specify the router protocol as wss |
74
|
|
|
* |
75
|
|
|
* @var bool |
76
|
|
|
*/ |
77
|
|
|
protected $tls = false; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var null|string |
81
|
|
|
*/ |
82
|
|
|
protected $path = null; |
83
|
|
|
|
84
|
|
|
protected $name = 'run:wamp-server {--realm=?} {--host=?} {--port=?} {--tls?} {--path=?} {--providers=*?} |
85
|
|
|
{--no-loop?} {--debug?} {--in-background?}'; |
86
|
|
|
protected $signature = 'run:wamp-server |
87
|
|
|
{--realm= : Specify WAMP realm to be used} |
88
|
|
|
{--host= : Specify the router host} |
89
|
|
|
{--port= : Specify the router port} |
90
|
|
|
{--tls : Specify the router protocol as wss} |
91
|
|
|
{--path= : Specify the router path component} |
92
|
|
|
{--providers=* : Register provider classes}, |
93
|
|
|
{--no-debug : Disable debug mode.} |
94
|
|
|
{--no-loop : Disable loop runner} |
95
|
|
|
{--no-in-background : Run in background mode with save process pid} |
96
|
|
|
'; |
97
|
|
|
protected $description = 'Run wamp server'; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Wamp server |
101
|
|
|
* |
102
|
|
|
* @var null|\sonrac\WAMP\Routers\Router |
103
|
|
|
*/ |
104
|
|
|
protected $WAMPServer = null; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Run server handle |
108
|
|
|
* |
109
|
|
|
* @throws \Exception |
110
|
|
|
*/ |
111
|
|
|
public function handle() |
112
|
|
|
{ |
113
|
|
|
$this->parseOptions(); |
114
|
|
|
|
115
|
|
|
$this->WAMPServer = app()->wampRouter; |
116
|
|
|
$transportProvider = new RatchetTransportProvider($this->host, $this->port); |
117
|
|
|
|
118
|
|
|
$this->WAMPServer->addTransportProvider($transportProvider); |
119
|
|
|
|
120
|
|
|
$this->WAMPServer->start(!$this->runOnce); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Merge config & input options |
125
|
|
|
*/ |
126
|
|
|
protected function parseOptions() |
127
|
|
|
{ |
128
|
|
|
$this->host = $this->getOptionFromInput('host') ?? $this->getConfig('host', $this->host); |
|
|
|
|
129
|
|
|
$this->port = $this->getOptionFromInput('port') ?? $this->getConfig('port', $this->port); |
|
|
|
|
130
|
|
|
$this->path = $this->getOptionFromInput('path') ?? $this->getConfig('path', $this->path); |
|
|
|
|
131
|
|
|
$this->realm = $this->getOptionFromInput('realm') ?? $this->getConfig('realm', $this->realm); |
|
|
|
|
132
|
|
|
$this->providers = $this->getOptionFromInput('providers') ?? $this->getConfig('providers', $this->providers); |
|
|
|
|
133
|
|
|
$this->tls = $this->getOptionFromInput('tls') ?? $this->getConfig('tls', $this->tls); |
134
|
|
|
|
135
|
|
|
$this->noDebug = $this->getOptionFromInput('no-debug') ?? $this->noDebug; |
|
|
|
|
136
|
|
|
$this->noInBackground = $this->getOptionFromInput('no-in-background') ?? $this->inBackground; |
|
|
|
|
137
|
|
|
$this->runOnce = $this->getOptionFromInput('no-loop') ?? $this->runOnce; |
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Get option value from input |
142
|
|
|
* |
143
|
|
|
* @param string $optionName |
144
|
|
|
* |
145
|
|
|
* @return array|null|string |
146
|
|
|
*/ |
147
|
|
|
protected function getOptionFromInput(string $optionName, $default = null) |
148
|
|
|
{ |
149
|
|
|
if (null === $this->input->getOption($optionName)) { |
150
|
|
|
return $default; |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $this->option($optionName); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get minion config |
158
|
|
|
* |
159
|
|
|
* @param string|null $optName Option name |
160
|
|
|
* @param mixed $default Default value |
161
|
|
|
* |
162
|
|
|
* @return array|string|int|null |
163
|
|
|
*/ |
164
|
|
|
protected function getConfig($optName = null, $default = null) |
165
|
|
|
{ |
166
|
|
|
$options = config('minion') ?? []; |
167
|
|
|
|
168
|
|
|
if (null === $optName) { |
169
|
|
|
return $options ?? []; |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
return isset($options[$optName]) ? $options[$optName] : $default; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
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.