blob: 0d5b33f40634d6be684d1a1258a1e9b9e4236e63 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php
declare(strict_types=1);
namespace Nsfisis\TinyPhpHttpd\PhpConKagawa2025;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Server\RequestHandlerInterface;
final readonly class NotFoundHandler implements RequestHandlerInterface
{
public function __construct(
private ResponseFactoryInterface $responseFactory,
private StreamFactoryInterface $streamFactory,
) {
}
public function handle(ServerRequestInterface $request): ResponseInterface
{
$body = '404 Not Found';
return $this->responseFactory->createResponse(404)
->withHeader('Content-Type', 'text/plain; charset=UTF-8')
->withBody($this->streamFactory->createStream($body));
}
}
|