1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace leocata\m1Bot; |
4
|
|
|
|
5
|
|
|
use leocata\M1\Api; |
6
|
|
|
use leocata\M1\HttpClientAuthorization; |
7
|
|
|
use Ratchet\Client\Connector; |
8
|
|
|
use Ratchet\Client\WebSocket; |
9
|
|
|
use Ratchet\RFC6455\Messaging\MessageInterface; |
10
|
|
|
use React\EventLoop\Factory; |
11
|
|
|
|
12
|
|
|
class CallbackWebSocket |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
private $subProtocol = 'json.api.smile-soft.com'; |
16
|
|
|
private $wssHost = 'wss://m1online.net'; |
17
|
|
|
private $host = 'm1online.net'; |
18
|
|
|
private $auth; |
19
|
|
|
|
20
|
|
|
public function __construct(HttpClientAuthorization $auth) |
21
|
|
|
{ |
22
|
|
|
$this->auth = $auth; |
23
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function execute() |
27
|
|
|
{ |
28
|
|
|
$apiWrapper = new Api($this->auth); |
29
|
|
|
|
30
|
|
|
$loop = Factory::create(); |
31
|
|
|
$connector = new Connector($loop); |
32
|
|
|
|
33
|
|
|
$gearman = new \GearmanClient(); |
|
|
|
|
34
|
|
|
$gearman->addServer(); |
35
|
|
|
|
36
|
|
|
$connector($this->wssHost, [$this->subProtocol], ['Host' => $this->host] + $this->auth->getBasicAuth())->then( |
37
|
|
|
|
38
|
|
|
function (WebSocket $stream) use ($gearman, $apiWrapper) { |
39
|
|
|
|
40
|
|
|
$stream->on('message', function (MessageInterface $msg) use ($gearman, $apiWrapper) { |
41
|
|
|
$result = $apiWrapper->getApiCallbackMethod($msg); |
42
|
|
|
$gearman->doHighBackground($result->getMethodName(), $msg); |
43
|
|
|
}); |
44
|
|
|
|
45
|
|
|
}, function (\Exception $e) use ($loop) { |
46
|
|
|
echo "Could not connect: {$e->getMessage()}\n"; |
47
|
|
|
$loop->stop(); |
48
|
|
|
} |
49
|
|
|
); |
50
|
|
|
|
51
|
|
|
$loop->run(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public function getHost(): string |
58
|
|
|
{ |
59
|
|
|
return $this->host; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @param string $host |
64
|
|
|
*/ |
65
|
|
|
public function setHost(string $host) |
66
|
|
|
{ |
67
|
|
|
$this->host = $host; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @return string |
72
|
|
|
*/ |
73
|
|
|
public function getWssHost(): string |
74
|
|
|
{ |
75
|
|
|
return $this->wssHost; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $wssHost |
80
|
|
|
*/ |
81
|
|
|
public function setWssHost(string $wssHost) |
82
|
|
|
{ |
83
|
|
|
$this->wssHost = $wssHost; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return string |
88
|
|
|
*/ |
89
|
|
|
public function getSubProtocol(): string |
90
|
|
|
{ |
91
|
|
|
return $this->subProtocol; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $subProtocol |
96
|
|
|
*/ |
97
|
|
|
public function setSubProtocol(string $subProtocol) |
98
|
|
|
{ |
99
|
|
|
$this->subProtocol = $subProtocol; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
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