Phred/src/Http/Controllers/OpenApiUiController.php

44 lines
1.3 KiB
PHP
Raw Normal View History

2026-01-06 17:02:05 +00:00
<?php
declare(strict_types=1);
namespace Phred\Http\Controllers;
use Phred\Support\Contracts\ConfigInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Nyholm\Psr7\Factory\Psr17Factory;
final class OpenApiUiController
{
public function __construct(
private ConfigInterface $config
) {}
public function __invoke(Request $request): ResponseInterface
{
$jsonUrl = $this->config->get('APP_URL', 'http://localhost:8000') . '/_phred/openapi.json';
$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<title>Phred API Documentation</title>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,400,700|Roboto:300,400,700" rel="stylesheet">
<style>body { margin: 0; padding: 0; }</style>
</head>
<body>
<redoc spec-url='{$jsonUrl}'></redoc>
<script src="https://cdn.jsdelivr.net/npm/redoc@next/bundles/redoc.standalone.js"> </script>
</body>
</html>
HTML;
return (new Psr17Factory())
->createResponse(200)
->withHeader('Content-Type', 'text/html')
->withBody((new Psr17Factory())->createStream($html));
}
}