Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
23 / 23
NotFoundResponse
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
23 / 23
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
23 / 23
1<?php
2
3namespace Miniframe\Response;
4
5use Miniframe\Core\Request;
6use Miniframe\Core\Response;
7
8class NotFoundResponse extends Response
9{
10    /**
11     * Initializes a basic 404 Not Found response
12     */
13    public function __construct()
14    {
15        $request = Request::getActual();
16
17        $code = 404;
18        $error = 'Not Found';
19        $message = 'The requested URL ' . $request->getServer('REQUEST_URI')
20                . ' was not found on this server.';
21
22        if ($request->getServer('HTTP_ACCEPT') == 'application/json') {
23            $text = json_encode([
24                'code' => $code,
25                'error' => $error,
26                'message' => $message,
27            ], JSON_PRETTY_PRINT);
28        } else {
29            $text = '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">' . PHP_EOL
30                . '<html><head>' . PHP_EOL
31                . '<title>' . htmlspecialchars($code . ' ' . $error) . '</title>' . PHP_EOL
32                . '</head><body>' . PHP_EOL
33                . '<h1>' . htmlspecialchars($error) . '</h1>' . PHP_EOL
34                . '<p>' . htmlspecialchars($message) . '</p>' . PHP_EOL
35                . '<hr>' . PHP_EOL
36                . ($request->getServer('SERVER_SIGNATURE') ?? '') . PHP_EOL
37                . '</body></html>';
38        }
39
40        parent::__construct($text, 1);
41        $this->setResponseCode($code);
42    }
43}