52 public function __construct( $httpCode, $content, $header =
null ) {
53 parent::__construct( (
string)$content );
54 $this->httpCode = (int)$httpCode;
55 $this->header = $header;
56 $this->content = $content;
78 return $this->httpCode;
89 HttpStatus::header( $this->httpCode );
90 header(
'Content-type: text/html; charset=utf-8' );
95 private function doLog() {
96 $logger = LoggerFactory::getInstance(
'HttpError' );
97 $content = $this->content;
99 if ( $content instanceof
Message ) {
100 $content = $content->
text();
105 'line' => $this->getLine(),
106 'http_code' => $this->httpCode,
109 $logMsg =
"$content ({http_code}) from {file}:{line}";
112 $logger->info( $logMsg, $context );
114 $logger->error( $logMsg, $context );
125 if ( $this->header ===
null ) {
126 $titleHtml = htmlspecialchars( HttpStatus::getMessage( $this->httpCode ) );
127 } elseif ( $this->header instanceof
Message ) {
128 $titleHtml = $this->header->escaped();
130 $titleHtml = htmlspecialchars( $this->header );
133 if ( $this->content instanceof
Message ) {
134 $contentHtml = $this->content->escaped();
136 $contentHtml = nl2br( htmlspecialchars( $this->content ) );
139 return "<!DOCTYPE html>\n" .
140 "<html><head><title>$titleHtml</title><meta name=\"color-scheme\" content=\"light dark\" /></head>\n" .
141 "<body><h1>$titleHtml</h1><p>$contentHtml</p></body></html>\n";
146class_alias( HttpError::class,
'HttpError' );
getFile()
Get the file for this page, if one exists.