You've already forked Traefik-Redis-Api
done. going to bed now.
This commit is contained in:
34
src/Http/JsonResponseFactory.php
Normal file
34
src/Http/JsonResponseFactory.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\App\Http;
|
||||
|
||||
use Nyholm\Psr7\Response;
|
||||
|
||||
/**
|
||||
* Class JsonResponseFactory
|
||||
*
|
||||
* A factory class for creating JSON responses.
|
||||
*/
|
||||
class JsonResponseFactory
|
||||
{
|
||||
/**
|
||||
* Create a JSON response with the given data and status code.
|
||||
*
|
||||
* @param array $data The data to include in the response.
|
||||
* @param int $statusCode The HTTP status code for the response.
|
||||
* @return Response The JSON response.
|
||||
* @throws \JsonException
|
||||
*/
|
||||
public static function createJsonResponse(array $data, int $statusCode = 200): Response
|
||||
{
|
||||
return new Response(
|
||||
status: $statusCode,
|
||||
headers: [
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
body: json_encode($data, JSON_THROW_ON_ERROR)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user