sonrac /
laravel-wamp
| 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 | class RunServer extends Command |
||||
| 20 | { |
||||
| 21 | use WAMPCommandTrait; |
||||
| 22 | /** |
||||
| 23 | * WAMP router host. |
||||
| 24 | * |
||||
| 25 | * @var string |
||||
| 26 | */ |
||||
| 27 | protected $host = '127.0.0.1'; |
||||
| 28 | |||||
| 29 | /** |
||||
| 30 | * {@inheritdoc} |
||||
| 31 | */ |
||||
| 32 | protected $name = 'wamp:run-server {--realm=?} {--host=?} {--port=?} {--tls?} {--transport-provider=?} |
||||
| 33 | {--no-loop?} {--no-debug?} {--in-background?} {--client-transport-provider=?} {--route-path=?}'; |
||||
| 34 | |||||
| 35 | /** |
||||
| 36 | * {@inheritdoc} |
||||
| 37 | */ |
||||
| 38 | protected $signature = 'wamp:run-server |
||||
| 39 | {--realm= : Specify WAMP realm to be used} |
||||
| 40 | {--host= : Specify the router host} |
||||
| 41 | {--port= : Specify the router port} |
||||
| 42 | {--tls : Specify the router protocol as wss} |
||||
| 43 | {--no-debug : Disable debug mode.} |
||||
| 44 | {--no-loop : Disable loop runner} |
||||
| 45 | {--transport-provider : Transport provider class} |
||||
| 46 | {--route-path= : Path to routes config} |
||||
| 47 | {--client-transport-provider= : Client transport provider class} |
||||
| 48 | {--in-background : Run task in background} |
||||
| 49 | '; |
||||
| 50 | |||||
| 51 | /** |
||||
| 52 | * {@inheritdoc} |
||||
| 53 | */ |
||||
| 54 | protected $description = 'Run wamp server'; |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * Wamp server. |
||||
| 58 | * |
||||
| 59 | * @var \Thruway\Peer\ClientInterface|\sonrac\WAMP\Client |
||||
| 60 | */ |
||||
| 61 | protected $WAMPServer = null; |
||||
| 62 | |||||
| 63 | /** |
||||
| 64 | * Client transport provider class. |
||||
| 65 | * |
||||
| 66 | * @var null|string |
||||
| 67 | * |
||||
| 68 | * @author Donii Sergii <[email protected]> |
||||
| 69 | */ |
||||
| 70 | protected $clientTransportProvider = null; |
||||
| 71 | |||||
| 72 | /** |
||||
| 73 | * Run server handle. |
||||
| 74 | * |
||||
| 75 | * @throws \Exception |
||||
| 76 | */ |
||||
| 77 | public function handle() |
||||
| 78 | { |
||||
| 79 | $this->parseOptions(); |
||||
| 80 | $this->changeWampLogger(); |
||||
| 81 | |||||
| 82 | if (!$this->runInBackground) { |
||||
| 83 | $this->WAMPServer = app()->wampRouter; |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 84 | $transportProvider = $this->getTransportProvider(); |
||||
| 85 | $this->WAMPServer->registerModule($transportProvider); |
||||
| 86 | $this->WAMPServer->start(!$this->runOnce); |
||||
| 87 | } else { |
||||
| 88 | $serverCommand = ' '.$this->getName().$this->getCommandLineOptions(); |
||||
| 89 | |||||
| 90 | if ($this->clientTransportProvider) { |
||||
| 91 | $serverCommand .= ' --client-transport-provider='.$this->clientTransportProvider; |
||||
| 92 | } |
||||
| 93 | |||||
| 94 | $this->addPidToLog(RunCommandInBackground::factory($serverCommand)->runInBackground(), |
||||
| 95 | DownWAMP::SERVER_PID_FILE); |
||||
| 96 | } |
||||
| 97 | } |
||||
| 98 | |||||
| 99 | /** |
||||
| 100 | * Run server handle |
||||
| 101 | * |
||||
| 102 | * @throws \Exception |
||||
| 103 | */ |
||||
| 104 | public function fire() |
||||
| 105 | { |
||||
| 106 | return $this->handle(); |
||||
|
0 ignored issues
–
show
Are you sure the usage of
$this->handle() targeting sonrac\WAMP\Commands\RunServer::handle() seems to always return null.
This check looks for function or method calls that always return null and whose return value is used. class A
{
function getObject()
{
return null;
}
}
$a = new A();
if ($a->getObject()) {
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. Loading history...
|
|||||
| 107 | } |
||||
| 108 | |||||
| 109 | /** |
||||
| 110 | * Get commandline options for background command |
||||
| 111 | * |
||||
| 112 | * @return string |
||||
| 113 | * |
||||
| 114 | * @author Donii Sergii <[email protected]> |
||||
| 115 | */ |
||||
| 116 | protected function getCommandLineOptions() |
||||
| 117 | { |
||||
| 118 | $command = ' --port='.$this->port. |
||||
| 119 | ' --host='.$this->host. |
||||
| 120 | ' --realm='.$this->realm; |
||||
| 121 | |||||
| 122 | if ($this->clientTransportProvider) { |
||||
| 123 | $command .= ' --transport-provider='.$this->clientTransportProvider; |
||||
| 124 | } |
||||
| 125 | |||||
| 126 | if ($this->noDebug) { |
||||
| 127 | $command .= ' --no-debug'; |
||||
| 128 | } |
||||
| 129 | |||||
| 130 | if ($this->tls) { |
||||
| 131 | $command .= ' --tls'; |
||||
| 132 | } |
||||
| 133 | |||||
| 134 | if ($this->routePath) { |
||||
| 135 | $command .= ' --route-path='.$this->routePath; |
||||
| 136 | } |
||||
| 137 | |||||
| 138 | if ($this->noLoop) { |
||||
| 139 | $command .= ' --no-loop'; |
||||
| 140 | } |
||||
| 141 | |||||
| 142 | return $command; |
||||
| 143 | } |
||||
| 144 | |||||
| 145 | /** |
||||
| 146 | * Merge config & input options. |
||||
| 147 | */ |
||||
| 148 | protected function parseOptions() |
||||
| 149 | { |
||||
| 150 | $this->clientTransportProvider = $this->getOptionFromInput('client-transport-provider'); |
||||
| 151 | $this->parseBaseOptions(); |
||||
| 152 | } |
||||
| 153 | |||||
| 154 | /** |
||||
| 155 | * Get WAMP server transport provider. |
||||
| 156 | * |
||||
| 157 | * @return null|string|\Thruway\Transport\RatchetTransportProvider |
||||
| 158 | * |
||||
| 159 | * @throws \sonrac\WAMP\Exceptions\InvalidWampTransportProvider |
||||
| 160 | * |
||||
| 161 | * @author Donii Sergii <[email protected]> |
||||
| 162 | */ |
||||
| 163 | protected function getTransportProvider() |
||||
| 164 | { |
||||
| 165 | if (is_object($this->transportProvider)) { |
||||
| 166 | return $this->transportProvider; |
||||
| 167 | } |
||||
| 168 | |||||
| 169 | if (is_null($this->transportProvider) || empty($this->transportProvider)) { |
||||
| 170 | $this->transportProvider = 'Thruway\Transport\RatchetTransportProvider'; |
||||
| 171 | } |
||||
| 172 | |||||
| 173 | if (is_string($this->transportProvider)) { |
||||
|
0 ignored issues
–
show
|
|||||
| 174 | return $this->transportProvider = new $this->transportProvider($this->host, $this->port); |
||||
| 175 | } |
||||
| 176 | |||||
| 177 | throw new InvalidWampTransportProvider(); |
||||
| 178 | } |
||||
| 179 | |||||
| 180 | /** |
||||
| 181 | * {@inheritdoc} |
||||
| 182 | * |
||||
| 183 | * @author Donii Sergii <[email protected]> |
||||
| 184 | */ |
||||
| 185 | protected function getLogger() |
||||
| 186 | { |
||||
| 187 | return app('wamp.server.logger'); |
||||
|
0 ignored issues
–
show
The function
app was not found. Maybe you did not declare it correctly or list all dependencies?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 188 | } |
||||
| 189 | } |
||||
| 190 |