1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ControleOnline\Command; |
4
|
|
|
|
5
|
|
|
use React\EventLoop\Loop; |
|
|
|
|
6
|
|
|
use React\Socket\Server; |
|
|
|
|
7
|
|
|
use React\Socket\ConnectionInterface; |
|
|
|
|
8
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
|
|
|
9
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
|
|
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
|
|
|
13
|
|
|
|
14
|
|
|
#[AsCommand( |
15
|
|
|
name: 'websocket:start', |
16
|
|
|
description: 'Inicia o servidor WebSocket com ReactPHP' |
17
|
|
|
)] |
18
|
|
|
class WebSocketServerCommand extends Command |
19
|
|
|
{ |
20
|
|
|
protected function configure(): void |
21
|
|
|
{ |
22
|
|
|
$this->addArgument('port', InputArgument::OPTIONAL, 'Porta para o servidor WebSocket', 8080); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
26
|
|
|
{ |
27
|
|
|
$port = $input->getArgument('port'); |
28
|
|
|
$output->writeln("Iniciando servidor WebSocket ReactPHP na porta {$port}..."); |
29
|
|
|
|
30
|
|
|
$loop = Loop::get(); |
31
|
|
|
$socket = new Server("0.0.0.0:{$port}", $loop); |
32
|
|
|
$clients = new \SplObjectStorage(); |
33
|
|
|
|
34
|
|
|
$socket->on('connection', function (ConnectionInterface $conn) use ($clients, $output) { |
35
|
|
|
$clients->attach($conn); |
36
|
|
|
$output->writeln("Nova conexão! ({$conn->resourceId})"); |
37
|
|
|
|
38
|
|
|
$conn->on('data', function ($data) use ($conn, $clients) { |
39
|
|
|
foreach ($clients as $client) { |
40
|
|
|
if ($client !== $conn) { |
41
|
|
|
$client->write($data); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
}); |
45
|
|
|
|
46
|
|
|
$conn->on('close', function () use ($conn, $clients, $output) { |
47
|
|
|
$clients->detach($conn); |
48
|
|
|
$output->writeln("Conexão fechada! ({$conn->resourceId})"); |
49
|
|
|
}); |
50
|
|
|
}); |
51
|
|
|
|
52
|
|
|
$output->writeln('Servidor WebSocket ReactPHP iniciado!'); |
53
|
|
|
$loop->run(); |
54
|
|
|
|
55
|
|
|
return Command::SUCCESS; |
56
|
|
|
} |
57
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths