|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Donii Sergii <[email protected]> |
|
5
|
|
|
* Date: 11/3/17 |
|
6
|
|
|
* Time: 5:58 PM |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace sonrac\WAMP\Commands; |
|
10
|
|
|
|
|
11
|
|
|
use Illuminate\Console\Command; |
|
12
|
|
|
use sonrac\WAMP\Client; |
|
13
|
|
|
use sonrac\WAMP\Exceptions\InvalidWampTransportProvider; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @class RegisterRoutes |
|
17
|
|
|
* <summary> |
|
18
|
|
|
* |
|
19
|
|
|
* @author Donii Sergii <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class RegisterRoutes extends Command |
|
22
|
|
|
{ |
|
23
|
|
|
use WAMPCommandTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
protected $name = 'wamp:register-routes {--realm=?} {--host=?} {--port=?} {--tls?} {--transport-provider=?} |
|
29
|
|
|
{--no-loop?} {--no-debug?} {--route-path=?}'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* {@inheritdoc} |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $description = 'Register wamp routes'; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* {@inheritdoc} |
|
38
|
|
|
*/ |
|
39
|
|
|
protected $signature = 'wamp:register-routes |
|
40
|
|
|
{--realm= : Specify WAMP realm to be used} |
|
41
|
|
|
{--host= : Specify the router host} |
|
42
|
|
|
{--port= : Specify the router port} |
|
43
|
|
|
{--path= : Specify the router path component} |
|
44
|
|
|
{--no-debug : Disable debug mode.} |
|
45
|
|
|
{--no-loop : Disable loop runner} |
|
46
|
|
|
{--route-path= : Path to routes config} |
|
47
|
|
|
{--tls : Specify the router protocol as wss} |
|
48
|
|
|
{--in-background : Run client in background} |
|
49
|
|
|
{--transport-provider= : Transport provider class}'; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Register wamp routes |
|
53
|
|
|
* |
|
54
|
|
|
* @author Donii Sergii <[email protected]> |
|
55
|
|
|
*/ |
|
56
|
|
|
public function fire() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->transportProvider = '\Thruway\Transport\PawlTransportProvider'; |
|
59
|
|
|
|
|
60
|
|
|
$this->parseOptions(); |
|
61
|
|
|
$this->changeWampLogger(); |
|
62
|
|
|
|
|
63
|
|
|
if (!$this->runInBackground) { |
|
64
|
|
|
if ($this->realm) { |
|
65
|
|
|
config('wamp.realm', $this->realm); |
|
|
|
|
|
|
66
|
|
|
app()->wampClient = new Client($this->realm); |
|
|
|
|
|
|
67
|
|
|
if ($this->routePath) { |
|
68
|
|
|
app()->wampClient->setRoutePath($this->routePath); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$client = app()->wampClient; |
|
73
|
|
|
$client->addTransportProvider($this->getTransportProvider()); |
|
74
|
|
|
$client->start(!$this->runOnce); |
|
75
|
|
|
} else { |
|
76
|
|
|
$command = $this->getName().($this->port ? ' --port='.$this->port : ''). |
|
|
|
|
|
|
77
|
|
|
($this->host ? ' --host='.$this->host : ''). |
|
|
|
|
|
|
78
|
|
|
($this->realm ? ' --realm='.$this->realm : ''); |
|
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
if ($this->transportProvider) { |
|
81
|
|
|
$command .= ' --transport-provider='.str_replace('\\', '\\\\', $this->transportProvider); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
if ($this->noDebug) { |
|
85
|
|
|
$command .= ' --no-debug'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
if ($this->tls) { |
|
89
|
|
|
$command .= ' --tls'; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if ($this->routePath) { |
|
93
|
|
|
$command .= ' --route-path='.$this->routePath; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if ($this->noLoop) { |
|
97
|
|
|
$command .= ' --no-loop'; |
|
98
|
|
|
} |
|
99
|
|
|
$this->addPidToLog(RunCommandInBackground::factory($command)->runInBackground(), DownWAMP::CLIENT_PID_FILE); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Register wamp routes |
|
105
|
|
|
* |
|
106
|
|
|
* @author Donii Sergii <[email protected]> |
|
107
|
|
|
*/ |
|
108
|
|
|
public function handle() |
|
109
|
|
|
{ |
|
110
|
|
|
return $this->fire(); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* {@inheritdoc} |
|
115
|
|
|
*/ |
|
116
|
|
|
protected function parseOptions() |
|
117
|
|
|
{ |
|
118
|
|
|
$this->parseBaseOptions(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Get WAMP client transport provider |
|
123
|
|
|
* |
|
124
|
|
|
* @return null|string|\Thruway\Transport\ClientTransportProviderInterface |
|
125
|
|
|
* |
|
126
|
|
|
* @throws \sonrac\WAMP\Exceptions\InvalidWampTransportProvider |
|
127
|
|
|
* |
|
128
|
|
|
* @author Donii Sergii <[email protected]> |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function getTransportProvider() |
|
131
|
|
|
{ |
|
132
|
|
|
if (is_object($this->transportProvider)) { |
|
133
|
|
|
return $this->transportProvider; |
|
|
|
|
|
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
if (is_null($this->transportProvider) || empty($this->transportProvider)) { |
|
137
|
|
|
$this->transportProvider = '\Thruway\Transport\PawlTransportProvider'; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
if (is_string($this->transportProvider)) { |
|
|
|
|
|
|
141
|
|
|
return $this->transportProvider = new $this->transportProvider($this->getTransportURI()); |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
throw new InvalidWampTransportProvider(); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Get transport url |
|
149
|
|
|
* |
|
150
|
|
|
* @author Donii Sergii <[email protected]> |
|
151
|
|
|
*/ |
|
152
|
|
|
protected function getTransportURI() |
|
153
|
|
|
{ |
|
154
|
|
|
return ($this->tls ? 'wss://' : 'ws://').$this->host.':'.$this->port; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* {@inheritdoc} |
|
159
|
|
|
* |
|
160
|
|
|
* @author Donii Sergii <[email protected]> |
|
161
|
|
|
*/ |
|
162
|
|
|
protected function getLogger() |
|
163
|
|
|
{ |
|
164
|
|
|
return app('wamp.client.logger'); |
|
|
|
|
|
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|