Skip to content

Commit 45cc31b

Browse files
committed
public handleEndpoint function
This will more easily allow end-users to call endpoints directly within an application without needing to initialize new instances of endpoint objects, thus losing state persistence.
1 parent 77792f3 commit 45cc31b

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/VerifierServer/Server.php

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)