Skip to content
Snippets Groups Projects
Commit 49cb754b authored by Stein Magne Bjorklund's avatar Stein Magne Bjorklund :speech_balloon:
Browse files

Merge branch '17-clean-up-class-httpstatus' into 'master'

Resolve "Clean up class HTTPStatus"

Closes #17

See merge request !15
parents 628f4f0b bc29fc6e
No related branches found
No related tags found
1 merge request!15Resolve "Clean up class HTTPStatus"
<?php <?php declare(strict_types=1);
namespace uib\ub\loadspeakr; namespace uib\ub\loadspeakr;
use stdClass; use stdClass;
class HTTPStatus final class HTTPStatus
{ {
public static function send303($uri, $ext) public static function send303($uri, $ext): void
{ {
header("HTTP/1.0 303 See Other"); header("HTTP/1.0 303 See Other");
header("Location: " . $uri); header("Location: " . $uri);
header("Content-type: " . $ext); header("Content-type: " . $ext);
echo HTTPStatus::_getContent("303", $uri); echo self::getContent("303", $uri);
exit(0); exit(0);
} }
public static function send401($uri) public static function send401($uri): void
{ {
header("HTTP/1.0 401 Forbidden"); header("HTTP/1.0 401 Forbidden");
echo HTTPStatus::_getContent("401", $uri); echo self::getContent("401", $uri);
exit(0); exit(0);
} }
public static function send404($uri) public static function send404($uri): void
{ {
header("HTTP/1.0 404 Not Found"); header("HTTP/1.0 404 Not Found");
$alt = "LODSPeaKr couldn't find the resource " . $uri; $alt = "LODSPeaKr couldn't find the resource " . $uri;
echo HTTPStatus::_getContent("404", $alt); echo self::getContent("404", $alt);
exit(0); exit(0);
} }
public static function send406($uri) public static function send406($uri): void
{ {
header("HTTP/1.0 406 Not Acceptable"); header("HTTP/1.0 406 Not Acceptable");
$alt = "LODSPeaKr can't return content acceptable according to the Accept headers sent in the request for " . $uri; $alt = "LODSPeaKr can't return content acceptable according to the Accept headers sent in the request for " . $uri;
echo HTTPStatus::_getContent("406", $alt); echo self::getContent("406", $alt);
exit(0); exit(0);
} }
public static function send500($uri) public static function send500($uri): void
{ {
header("HTTP/1.0 500 Internal Server Error"); header("HTTP/1.0 500 Internal Server Error");
$alt = "There was an internal error when processing " . $uri; $alt = "There was an internal error when processing " . $uri;
echo HTTPStatus::_getContent("500", $alt); echo self::getContent("500", $alt);
exit(0); exit(0);
} }
private static function _getContent($n, $alt) private static function getContent($n, $alt): string
{ {
global $conf; global $conf;
global $lodspk; global $lodspk;
...@@ -54,17 +54,13 @@ class HTTPStatus ...@@ -54,17 +54,13 @@ class HTTPStatus
$lodspk['home'] = $conf['basedir']; $lodspk['home'] = $conf['basedir'];
$lodspk['baseUrl'] = $conf['basedir']; $lodspk['baseUrl'] = $conf['basedir'];
$lodspk['ns'] = $conf['ns']; $lodspk['ns'] = $conf['ns'];
$lodspk['this']['value'] = $uri;
$lodspk['this']['curie'] = Utils::uri2curie($uri);
$lodspk['this']['local'] = $localUri;
$file = $conf['httpStatus']['directory'] . "/" . $n . ".template"; $file = $conf['httpStatus']['directory'] . "/" . $n . ".template";
if (file_exists($conf['home'] . $file)) { if (file_exists($conf['home'] . $file)) {
require_once("Utils.php");
Utils::showView($lodspk, new stdClass(), $file); Utils::showView($lodspk, new stdClass(), $file);
} else { return '';
return $alt . "\n\n";
} }
return $alt . "\n\n";
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment