1 | <?php |
||
25 | class StreamClient |
||
26 | { |
||
27 | |||
28 | /** |
||
29 | * Stream pattern END_OF_MESSAGE |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | const END_OF_MESSAGE = "/\r\n\r\n|\n\n|\r\r/"; |
||
34 | |||
35 | /** |
||
36 | * Client for send request |
||
37 | * |
||
38 | * @var GuzzleHttp\Client $client |
||
39 | */ |
||
40 | private $client; |
||
41 | |||
42 | /** |
||
43 | * Responce object from rest |
||
44 | * |
||
45 | * @var GuzzleHttp\Psr7\Response $response |
||
46 | */ |
||
47 | private $response; |
||
48 | |||
49 | /** |
||
50 | * Request url to send request |
||
51 | * |
||
52 | * @var string $url |
||
53 | */ |
||
54 | private $url; |
||
55 | |||
56 | /** |
||
57 | * Request options to add to url |
||
58 | * |
||
59 | * @var string |
||
60 | */ |
||
61 | private $options = []; |
||
62 | |||
63 | /** |
||
64 | * Last received message id |
||
65 | * |
||
66 | * @var string $lastMessageId |
||
67 | */ |
||
68 | private $lastMessageId; |
||
69 | |||
70 | /** |
||
71 | * Reconnection time in milliseconds |
||
72 | * |
||
73 | * @var integer $retry |
||
74 | */ |
||
75 | private $retry = 3000; |
||
76 | |||
77 | /** |
||
78 | * Constructor |
||
79 | * |
||
80 | * @param string $url |
||
81 | * @param integer $requestDelay |
||
82 | * @throws InvaliArgumentException |
||
83 | */ |
||
84 | public function __construct($url, $requestDelay, $options) |
||
96 | |||
97 | /** |
||
98 | * Create client |
||
99 | */ |
||
100 | private function createClientObject() |
||
114 | |||
115 | /** |
||
116 | * |
||
117 | * @return string $lastMessageId |
||
118 | */ |
||
119 | public function getLastMessageId(): string |
||
123 | |||
124 | /** |
||
125 | * |
||
126 | * @param string $lastMessageId |
||
127 | */ |
||
128 | public function setLastMessageId($lastMessageId) |
||
132 | |||
133 | /** |
||
134 | * Connect to firebase server |
||
135 | * |
||
136 | * @throws RuntimeException |
||
137 | */ |
||
138 | private function connect() |
||
147 | |||
148 | /** |
||
149 | * Create url with or without query options |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | private function createUrl(): string |
||
157 | |||
158 | /** |
||
159 | * Send Request |
||
160 | */ |
||
161 | private function sendRequest() |
||
177 | |||
178 | |||
179 | /** |
||
180 | * Returns generator that yields new event when it's available on stream. |
||
181 | */ |
||
182 | public function getEvents() |
||
225 | } |
||
226 |