62 lines
2.2 KiB
PHP
62 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Lean\Factory;
|
|
|
|
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse};
|
|
use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse };
|
|
use Laminas\Diactoros\Response;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class HttpFactory implements HttpFactoryInterface
|
|
{
|
|
public static function createResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
|
{
|
|
return new Response($url, $code, $headers);
|
|
}
|
|
|
|
public static function createRedirectResponse(string $url, int $code = 302, array $headers = []) : ResponseInterface
|
|
{
|
|
return new RedirectResponse($url, $code, $headers);
|
|
}
|
|
|
|
public static function createHtmlResponse(string $html, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new HtmlResponse($html, $code, $headers);
|
|
}
|
|
|
|
public static function createTextResponse(string $text, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new TextResponse($text, $code, $headers);
|
|
}
|
|
|
|
public static function createJsonResponse(mixed $data, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new JsonResponse($data, $code, $headers);
|
|
}
|
|
|
|
public static function createEmptyResponse(int $code = 204, array $headers = []) : ResponseInterface
|
|
{
|
|
return new EmptyResponse($code, $headers);
|
|
}
|
|
|
|
public static function createPdfResponse(\Stringable|string $binary, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new PdfResponse((string) $binary, $code, $headers);
|
|
}
|
|
|
|
public static function createDownloadableResponse(string $data, string $filename, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new DownloadResponse($data, $filename, $code, $headers);
|
|
}
|
|
|
|
public static function createImageResponse(string $data, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new ImageResponse($data, $code, $headers);
|
|
}
|
|
|
|
public static function createFileDownloadResponse(string $path, int $code = 200, array $headers = []) : ResponseInterface
|
|
{
|
|
return new FileDownloadResponse($path, $code, $headers);
|
|
}
|
|
}
|