@@ -240,6 +240,32 @@ public static function arrayToRequestString(array $formData): string
240240 return implode (PHP_EOL , array_map (fn ($ key , $ value ) => $ key . ': ' . $ value , array_keys ($ formData ), $ formData ));
241241 }
242242
243+ /**
244+ * Handles the incoming HTTP request and generates the appropriate response.
245+ *
246+ * @param string $uri The URI of the request.
247+ * @param string $method The HTTP method of the request (e.g., 'GET', 'POST').
248+ * @param ServerRequestInterface|string $request The request payload, typically used for 'POST' requests.
249+ * @param int|string &$response The variable to store the generated response.
250+ * @param array &$content_type The variable to store the content type of the response.
251+ * @param string &$body The variable to store the body of the response.
252+ * @param bool $bypass_token Whether to bypass the token check.
253+ */
254+ public function handleEndpoint (
255+ string $ uri ,
256+ string $ method ,
257+ ServerRequestInterface |string $ request ,
258+ int |string &$ response ,
259+ array &$ content_type ,
260+ string &$ body ,
261+ bool $ bypass_token = false
262+ ): void
263+ {
264+ if (isset ($ this ->endpoints [$ uri ]) && $ this ->endpoints [$ uri ] instanceof EndpointInterface) {
265+ $ this ->endpoints [$ uri ]->handle ($ method , $ request , $ response , $ content_type , $ body , $ bypass_token );
266+ }
267+ }
268+
243269 /**
244270 * Handles an incoming resource request from a client and generates appropriate responses.
245271 *
@@ -257,15 +283,7 @@ private function handleReact(ServerRequestInterface $client): ResponseInterface
257283 $ content_type = ['Content-Type ' => 'text/plain ' ];
258284 $ body = "Not Found " ;
259285
260- if (isset ($ this ->endpoints [$ uri ]) && $ this ->endpoints [$ uri ] instanceof EndpointInterface) {
261- $ this ->endpoints [$ uri ]->handle (
262- $ method ,
263- $ client ,
264- $ response ,
265- $ content_type ,
266- $ body
267- );
268- }
286+ $ this ->handleEndpoint ($ uri , $ method , $ client , $ response , $ content_type , $ body );
269287
270288 return new Response (
271289 $ response ,
0 commit comments