1 | <?php |
||
23 | abstract class Controller implements HttpServerInterface |
||
24 | { |
||
25 | /** |
||
26 | * The request buffer. |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | protected $requestBuffer = ''; |
||
31 | |||
32 | /** |
||
33 | * The incoming request. |
||
34 | * |
||
35 | * @var \Psr\Http\Message\RequestInterface |
||
36 | */ |
||
37 | protected $request; |
||
38 | |||
39 | /** |
||
40 | * The content length that will |
||
41 | * be calculated. |
||
42 | * |
||
43 | * @var int |
||
44 | */ |
||
45 | protected $contentLength; |
||
46 | |||
47 | /** |
||
48 | * The channel manager. |
||
49 | * |
||
50 | * @var \BeyondCode\LaravelWebSockets\Contracts\ChannelManager |
||
51 | */ |
||
52 | protected $channelManager; |
||
53 | |||
54 | /** |
||
55 | * Initialize the request. |
||
56 | * |
||
57 | * @param ChannelManager $channelManager |
||
58 | * @return void |
||
|
|||
59 | */ |
||
60 | public function __construct(ChannelManager $channelManager) |
||
64 | |||
65 | /** |
||
66 | * Handle the opened socket connection. |
||
67 | * |
||
68 | * @param \Ratchet\ConnectionInterface $connection |
||
69 | * @param \Psr\Http\Message\RequestInterface $request |
||
70 | * @return void |
||
71 | */ |
||
72 | public function onOpen(ConnectionInterface $connection, RequestInterface $request = null) |
||
86 | |||
87 | /** |
||
88 | * Handle the oncoming message and add it to buffer. |
||
89 | * |
||
90 | * @param \Ratchet\ConnectionInterface $from |
||
91 | * @param mixed $msg |
||
92 | * @return void |
||
93 | */ |
||
94 | public function onMessage(ConnectionInterface $from, $msg) |
||
104 | |||
105 | /** |
||
106 | * Handle the socket closing. |
||
107 | * |
||
108 | * @param \Ratchet\ConnectionInterface $connection |
||
109 | * @return void |
||
110 | */ |
||
111 | public function onClose(ConnectionInterface $connection) |
||
115 | |||
116 | /** |
||
117 | * Handle the errors. |
||
118 | * |
||
119 | * @param \Ratchet\ConnectionInterface $connection |
||
120 | * @param Exception $exception |
||
121 | * @return void |
||
122 | */ |
||
123 | public function onError(ConnectionInterface $connection, Exception $exception) |
||
137 | |||
138 | /** |
||
139 | * Get the content length from the headers. |
||
140 | * |
||
141 | * @param array $headers |
||
142 | * @return int |
||
143 | */ |
||
144 | protected function findContentLength(array $headers): int |
||
150 | |||
151 | /** |
||
152 | * Check the content length. |
||
153 | * |
||
154 | * @return bool |
||
155 | */ |
||
156 | protected function verifyContentLength() |
||
160 | |||
161 | /** |
||
162 | * Handle the oncoming connection. |
||
163 | * |
||
164 | * @param \Ratchet\ConnectionInterface $connection |
||
165 | * @return void |
||
166 | */ |
||
167 | protected function handleRequest(ConnectionInterface $connection) |
||
201 | |||
202 | /** |
||
203 | * Send the response and close the connection. |
||
204 | * |
||
205 | * @param \Ratchet\ConnectionInterface $connection |
||
206 | * @param mixed $response |
||
207 | * @return void |
||
208 | */ |
||
209 | protected function sendAndClose(ConnectionInterface $connection, $response) |
||
213 | |||
214 | /** |
||
215 | * Ensure app existence. |
||
216 | * |
||
217 | * @param mixed $appId |
||
218 | * @return $this |
||
219 | * @throws \Symfony\Component\HttpKernel\Exception\HttpException |
||
220 | */ |
||
221 | public function ensureValidAppId($appId) |
||
229 | |||
230 | /** |
||
231 | * Ensure signature integrity coming from an |
||
232 | * authorized application. |
||
233 | * |
||
234 | * @param \GuzzleHttp\Psr7\ServerRequest $request |
||
235 | * @return $this |
||
236 | * @throws \Symfony\Component\HttpKernel\Exception\HttpException |
||
237 | */ |
||
238 | protected function ensureValidSignature(Request $request) |
||
265 | |||
266 | /** |
||
267 | * Handle the incoming request. |
||
268 | * |
||
269 | * @param \Illuminate\Http\Request $request |
||
270 | * @return void |
||
271 | */ |
||
272 | abstract public function __invoke(Request $request); |
||
273 | } |
||
274 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.