forked from simplesamlphp/simplesamlphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotFound.php
More file actions
68 lines (58 loc) · 1.84 KB
/
NotFound.php
File metadata and controls
68 lines (58 loc) · 1.84 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
namespace SimpleSAML\Error;
use SimpleSAML\Utils;
/**
* Exception which will show a 404 Not Found error page.
*
* This exception can be thrown from within a module page handler. The user will then be shown a 404 Not Found error
* page.
*
* @package SimpleSAMLphp
*/
class NotFound extends Error
{
/**
* Create a new NotFound error
*
* @param string $reason Optional description of why the given page could not be found.
* @throws \SimpleSAML\Error\CriticalConfigurationError
* @throws \Exception
*/
public function __construct(
private ?string $reason = null,
) {
$httpUtils = new Utils\HTTP();
$url = $httpUtils->getSelfURL();
if ($reason === null) {
parent::__construct([ErrorCodes::NOTFOUND, '%URL%' => $url], null, 404);
$this->message = "The requested page '$url' could not be found.";
} else {
parent::__construct([ErrorCodes::NOTFOUNDREASON, '%URL%' => $url, '%REASON%' => $reason], null, 404);
$this->message = "The requested page '$url' could not be found. " . $reason;
}
}
/**
* Retrieve the reason why the given page could not be found.
*
* @return string|null The reason why the page could not be found.
*/
public function getReason(): ?string
{
return $this->reason;
}
/**
* NotFound exceptions don't need to display a backtrace, as they are very simple and the trace is usually trivial,
* so just log the message without any backtrace at all.
*
* @param bool $anonymize Whether to anonymize the trace or not.
*
* @return string[]
*/
public function format(bool $anonymize = false): array
{
return [
$this->getClass() . ': ' . $this->getMessage(),
];
}
}