-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServeCommand.php
More file actions
55 lines (40 loc) · 1.47 KB
/
Copy pathServeCommand.php
File metadata and controls
55 lines (40 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
namespace Micilini\PhpSockets\Laravel\Commands;
use Illuminate\Console\Command;
use Micilini\PhpSockets\Laravel\PhpSocketsManager;
use Throwable;
final class ServeCommand extends Command
{
protected $signature = 'phpsockets:serve
{--host= : Override configured WebSocket host}
{--port= : Override configured WebSocket port}
{--debug : Enable debug logs for this run}';
protected $description = 'Start the PHPSockets WebSocket chat server from Laravel.';
public function handle(PhpSocketsManager $manager): int
{
$overrides = [];
$host = $this->option('host');
if (is_string($host) && $host !== '') {
$overrides['host'] = $host;
}
$port = $this->option('port');
if (is_string($port) && $port !== '') {
$overrides['port'] = (int) $port;
}
if ((bool) $this->option('debug')) {
$overrides['debug'] = true;
}
try {
$serverConfig = $manager->serverConfig($overrides);
$server = $manager->server($overrides);
$this->components->info("Starting PHPSockets on {$serverConfig->host}:{$serverConfig->port}");
$this->line('Press CTRL+C to stop.');
$server->run();
return self::SUCCESS;
} catch (Throwable $exception) {
$this->components->error($exception->getMessage());
return self::FAILURE;
}
}
}