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
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class RunServer |
16
|
|
|
* Run WAMP server command |
17
|
|
|
* |
18
|
|
|
* @package sonrac\WAMP\Commands |
19
|
|
|
*/ |
20
|
|
|
class RunServer extends Command |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* WAMP router host |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $host; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Wamp realm to used |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
protected $realm; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Providers list |
38
|
|
|
* |
39
|
|
|
* @var array |
40
|
|
|
*/ |
41
|
|
|
protected $providers = []; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* WAMP router port |
45
|
|
|
* |
46
|
|
|
* @var int |
47
|
|
|
*/ |
48
|
|
|
protected $port; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Run in debug mode. If `in-background` option is disable, logging to storage_path('server-{pid}.log') |
52
|
|
|
* |
53
|
|
|
* @var bool |
54
|
|
|
*/ |
55
|
|
|
protected $debug = false; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Run command in background |
59
|
|
|
* |
60
|
|
|
* @var bool |
61
|
|
|
*/ |
62
|
|
|
protected $inBackground = false; |
63
|
|
|
|
64
|
|
|
protected $name = 'Run WAMP server'; |
65
|
|
|
protected $description = 'Run wamp server'; |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* {@inheritdoc} |
69
|
|
|
*/ |
70
|
1 |
|
protected function getOptions() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
1 |
|
['realm', null, InputOption::VALUE_OPTIONAL, 'Specify WAMP realm to be used'], |
74
|
1 |
|
['host', null, InputOption::VALUE_OPTIONAL, 'Specify the router host'], |
75
|
1 |
|
['port', null, InputOption::VALUE_OPTIONAL, 'Specify the router port'], |
76
|
1 |
|
['tls', null, InputOption::VALUE_NONE, 'Specify the router protocol as wss'], |
77
|
1 |
|
['path', null, InputOption::VALUE_OPTIONAL, 'Specify the router path component'], |
78
|
1 |
|
['providers', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Register provider classes'], |
79
|
1 |
|
['debug', null, InputOption::VALUE_NONE, 'Run in debug mode outputting all trasport messages.'], |
80
|
|
|
[ |
81
|
1 |
|
'in-background', |
82
|
|
|
null, |
83
|
1 |
|
InputOption::VALUE_NONE | InputOption::VALUE_OPTIONAL, |
84
|
1 |
|
'Run in background mode with save process pid' |
85
|
|
|
] |
86
|
|
|
]; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Run server handle |
91
|
|
|
*/ |
92
|
|
|
protected function handle() |
93
|
|
|
{ |
94
|
|
|
$this->parseOptions(); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Merge config & input options |
99
|
|
|
*/ |
100
|
|
|
protected function parseOptions() { |
101
|
|
|
$this->host = $this->getOptionFromInput('host') ?? $this->getConfig('host'); |
|
|
|
|
102
|
|
|
$this->port = $this->getOptionFromInput('port') ?? $this->getConfig('port'); |
|
|
|
|
103
|
|
|
$this->realm = $this->getOptionFromInput('realm') ?? $this->getConfig('realm'); |
|
|
|
|
104
|
|
|
$this->providers = $this->getOptionFromInput('providers') ?? $this->getConfig('providers'); |
|
|
|
|
105
|
|
|
$this->tls = $this->getOptionFromInput('tls') ?? $this->getConfig('tls'); |
|
|
|
|
106
|
|
|
$this->debug = $this->getOptionFromInput('debug') ?? $this->debug; |
|
|
|
|
107
|
|
|
$this->inBackground = $this->getOptionFromInput('in-background') ?? $this->inBackground; |
|
|
|
|
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Get option value from input |
112
|
|
|
* |
113
|
|
|
* @param string $optionName |
114
|
|
|
* |
115
|
|
|
* @return array|null|string |
116
|
|
|
*/ |
117
|
|
|
protected function getOptionFromInput(string $optionName) { |
118
|
|
|
if (!$this->hasOption($optionName)) { |
119
|
|
|
return null; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
return $this->option($optionName); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* Get minion config |
127
|
|
|
* |
128
|
|
|
* @param string|null $optName Option name |
129
|
|
|
* |
130
|
|
|
* @return array|string|int|null |
131
|
|
|
*/ |
132
|
|
|
protected function getConfig($optName = null) |
133
|
|
|
{ |
134
|
|
|
$options = config('minion') ?? []; |
135
|
|
|
|
136
|
|
|
if (null === $optName) { |
137
|
|
|
return $options ?? []; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return isset($options[$optName]) ? $options[$optName] : null; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
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.