1 | <?php |
||
18 | class Server |
||
19 | { |
||
20 | private $input; |
||
21 | private $output; |
||
22 | private $questionHelper; |
||
23 | private $loop; |
||
24 | private $port; |
||
25 | |||
26 | 11 | public function __construct( |
|
36 | |||
37 | 11 | public function start() |
|
38 | { |
||
39 | 11 | $this->loop = React\EventLoop\Factory::create(); |
|
40 | $server = new React\Http\Server($this->loop, function (ServerRequestInterface $request) { |
||
41 | try { |
||
42 | 1 | return $this->router($request); |
|
43 | } catch (Throwable $exception) { |
||
44 | Deployer::printException($this->output, $exception); |
||
45 | return new React\Http\Message\Response(500, ['Content-Type' => 'text/plain'], 'Master error: ' . $exception->getMessage()); |
||
46 | } |
||
47 | 11 | }); |
|
48 | 11 | $socket = new React\Socket\Server(0, $this->loop); |
|
49 | 11 | $server->listen($socket); |
|
50 | 11 | $address = $socket->getAddress(); |
|
51 | 11 | $this->port = parse_url($address, PHP_URL_PORT); |
|
52 | 11 | } |
|
53 | |||
54 | 1 | private function router(ServerRequestInterface $request): Response |
|
55 | { |
||
56 | 1 | switch ($request->getUri()->getPath()) { |
|
57 | 1 | case '/proxy': |
|
58 | 1 | $body = $request->getBody(); |
|
59 | 1 | ['host' => $host, 'func' => $func, 'arguments' => $arguments] = json_decode($body, true); |
|
60 | |||
61 | 1 | Context::push(new Context(getHost($host), $this->input, $this->output)); |
|
62 | 1 | $answer = call_user_func($func, ...$arguments); |
|
63 | 1 | Context::pop(); |
|
64 | |||
65 | 1 | return new Response(200, ['Content-Type' => 'application/json'], json_encode($answer)); |
|
66 | break; |
||
67 | |||
68 | default: |
||
69 | throw new Exception('Server path not found: ' . $request->getUri()->getPath()); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | 2 | public function addPeriodicTimer($interval, $callback) |
|
77 | |||
78 | 2 | public function run() |
|
82 | |||
83 | 2 | public function stop() |
|
87 | |||
88 | 2 | public function getPort(): int |
|
92 | } |
||
93 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.