|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Conveyor\SocketHandlers\Abstractions; |
|
4
|
|
|
|
|
5
|
|
|
use Slim\Container; |
|
|
|
|
|
|
6
|
|
|
use Conveyor\SocketHandlers\Interfaces\SocketHandlerInterface; |
|
7
|
|
|
use Conveyor\Actions\Interfaces\ActionInterface; |
|
8
|
|
|
|
|
9
|
|
|
abstract class SocketHandler implements SocketHandlerInterface |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @param string $data |
|
13
|
|
|
* @param int $fd |
|
14
|
|
|
*/ |
|
15
|
|
|
public function __invoke(string $data, $fd = null) |
|
16
|
|
|
{ |
|
17
|
|
|
/** @var ActionInterface */ |
|
18
|
|
|
$action = $this->parseData($data); |
|
19
|
|
|
|
|
20
|
|
|
$this->maybeSetFd($fd); |
|
21
|
|
|
|
|
22
|
|
|
return $action->execute(); |
|
|
|
|
|
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Set $fd (File descriptor) if method "setFd" exists. |
|
27
|
|
|
* |
|
28
|
|
|
* @param int|null $fd File descriptor. |
|
29
|
|
|
* |
|
30
|
|
|
* @return void |
|
31
|
|
|
*/ |
|
32
|
|
|
public function maybeSetFd($fd = null): void { |
|
33
|
|
|
$parsedData = $this->getParsedData(); |
|
|
|
|
|
|
34
|
|
|
$action = $this->getAction($parsedData['action']); |
|
|
|
|
|
|
35
|
|
|
|
|
36
|
|
|
if ($fd && method_exists($action, 'setFd')) { |
|
|
|
|
|
|
37
|
|
|
$action->setFd($fd); |
|
38
|
|
|
} |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Set $server if method "setServer" exists. |
|
43
|
|
|
* |
|
44
|
|
|
* @param mixed $server Server object, e.g. Swoole\WebSocket\Frame. |
|
45
|
|
|
* |
|
46
|
|
|
* @return void |
|
47
|
|
|
*/ |
|
48
|
|
|
public function maybeSetServer($server = null): void { |
|
49
|
|
|
$parsedData = $this->getParsedData(); |
|
50
|
|
|
$action = $this->getAction($parsedData['action']); |
|
51
|
|
|
|
|
52
|
|
|
if ($server && method_exists($action, 'setServer')) { |
|
53
|
|
|
$action->setServer($server); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* This method identifies the action to be executed |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $data |
|
61
|
|
|
* |
|
62
|
|
|
* @return ActionInterface |
|
63
|
|
|
* |
|
64
|
|
|
* @throws InvalidArgumentException |
|
65
|
|
|
*/ |
|
66
|
|
|
abstract public function parseData(string $data) : ActionInterface; |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @param array $data |
|
70
|
|
|
* |
|
71
|
|
|
* @return void |
|
72
|
|
|
* |
|
73
|
|
|
* @throws InvalidArgumentException |
|
74
|
|
|
*/ |
|
75
|
|
|
abstract public function validateData(array $data) : void; |
|
76
|
|
|
} |
|
77
|
|
|
|
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