and \
)
*/
public function __construct( $httpCode, $content, $header = null ) {
parent::__construct( $content );
$this->httpCode = (int)$httpCode;
$this->header = $header;
$this->content = $content;
}
/**
* Returns the HTTP status code supplied to the constructor.
*
* @return int
*/
public function getStatusCode() {
return $this->httpCode;
}
/**
* Report the HTTP error.
* Sends the appropriate HTTP status code and outputs an
* HTML page with an error message.
*/
public function report() {
$httpMessage = HttpStatus::getMessage( $this->httpCode );
header( "Status: {$this->httpCode} {$httpMessage}", true, $this->httpCode );
header( 'Content-type: text/html; charset=utf-8' );
print $this->getHTML();
}
/**
* Returns HTML for reporting the HTTP error.
* This will be a minimal but complete HTML document.
*
* @return string HTML
*/
public function getHTML() {
if ( $this->header === null ) {
$header = HttpStatus::getMessage( $this->httpCode );
} elseif ( $this->header instanceof Message ) {
$header = $this->header->escaped();
} else {
$header = htmlspecialchars( $this->header );
}
if ( $this->content instanceof Message ) {
$content = $this->content->escaped();
} else {
$content = htmlspecialchars( $this->content );
}
return "\n" .
"$header\n" .
"$header
$content
\n";
}
}