1 | <?php |
||
24 | abstract class Controller implements HttpServerInterface |
||
25 | { |
||
26 | /** |
||
27 | * The request buffer. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $requestBuffer = ''; |
||
32 | |||
33 | /** |
||
34 | * The incoming request. |
||
35 | * |
||
36 | * @var \Psr\Http\Message\RequestInterface |
||
37 | */ |
||
38 | protected $request; |
||
39 | |||
40 | /** |
||
41 | * The content length that will |
||
42 | * be calculated. |
||
43 | * |
||
44 | * @var int |
||
45 | */ |
||
46 | protected $contentLength; |
||
47 | |||
48 | /** |
||
49 | * The channel manager. |
||
50 | * |
||
51 | * @var \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager |
||
52 | */ |
||
53 | protected $channelManager; |
||
54 | |||
55 | /** |
||
56 | * The replicator driver. |
||
57 | * |
||
58 | * @var \BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface |
||
59 | */ |
||
60 | protected $replicator; |
||
61 | |||
62 | /** |
||
63 | * Initialize the request. |
||
64 | * |
||
65 | * @param \BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager $channelManager |
||
66 | * @param \BeyondCode\LaravelWebSockets\PubSub\ReplicationInterface $replicator |
||
67 | * @return void |
||
|
|||
68 | */ |
||
69 | public function __construct(ChannelManager $channelManager, ReplicationInterface $replicator) |
||
74 | |||
75 | /** |
||
76 | * Handle the opened socket connection. |
||
77 | * |
||
78 | * @param \Ratchet\ConnectionInterface $connection |
||
79 | * @param \Psr\Http\Message\RequestInterface $request |
||
80 | * @return void |
||
81 | */ |
||
82 | public function onOpen(ConnectionInterface $connection, RequestInterface $request = null) |
||
96 | |||
97 | /** |
||
98 | * Handle the oncoming message and add it to buffer. |
||
99 | * |
||
100 | * @param \Ratchet\ConnectionInterface $from |
||
101 | * @param mixed $msg |
||
102 | * @return void |
||
103 | */ |
||
104 | public function onMessage(ConnectionInterface $from, $msg) |
||
114 | |||
115 | /** |
||
116 | * Handle the socket closing. |
||
117 | * |
||
118 | * @param \Ratchet\ConnectionInterface $connection |
||
119 | * @return void |
||
120 | */ |
||
121 | public function onClose(ConnectionInterface $connection) |
||
125 | |||
126 | /** |
||
127 | * Handle the errors. |
||
128 | * |
||
129 | * @param \Ratchet\ConnectionInterface $connection |
||
130 | * @param Exception $exception |
||
131 | * @return void |
||
132 | */ |
||
133 | public function onError(ConnectionInterface $connection, Exception $exception) |
||
147 | |||
148 | /** |
||
149 | * Get the content length from the headers. |
||
150 | * |
||
151 | * @param array $headers |
||
152 | * @return int |
||
153 | */ |
||
154 | protected function findContentLength(array $headers): int |
||
160 | |||
161 | /** |
||
162 | * Check the content length. |
||
163 | * |
||
164 | * @return bool |
||
165 | */ |
||
166 | protected function verifyContentLength() |
||
170 | |||
171 | /** |
||
172 | * Handle the oncoming connection. |
||
173 | * |
||
174 | * @param \Ratchet\ConnectionInterface $connection |
||
175 | * @return void |
||
176 | */ |
||
177 | protected function handleRequest(ConnectionInterface $connection) |
||
207 | |||
208 | /** |
||
209 | * Send the response and close the connection. |
||
210 | * |
||
211 | * @param \Ratchet\ConnectionInterface $connection |
||
212 | * @param mixed $response |
||
213 | * @return void |
||
214 | */ |
||
215 | protected function sendAndClose(ConnectionInterface $connection, $response) |
||
219 | |||
220 | /** |
||
221 | * Ensure app existence. |
||
222 | * |
||
223 | * @param mixed $appId |
||
224 | * @return $this |
||
225 | * @throws \Symfony\Component\HttpKernel\Exception\HttpException |
||
226 | */ |
||
227 | public function ensureValidAppId($appId) |
||
235 | |||
236 | /** |
||
237 | * Ensure signature integrity coming from an |
||
238 | * authorized application. |
||
239 | * |
||
240 | * @param \GuzzleHttp\Psr7\ServerRequest $request |
||
241 | * @return $this |
||
242 | * @throws \Symfony\Component\HttpKernel\Exception\HttpException |
||
243 | */ |
||
244 | protected function ensureValidSignature(Request $request) |
||
268 | |||
269 | /** |
||
270 | * Handle the incoming request. |
||
271 | * |
||
272 | * @param \Illuminate\Http\Request $request |
||
273 | * @return void |
||
274 | */ |
||
275 | abstract public function __invoke(Request $request); |
||
276 | } |
||
277 |
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.