diff --git a/utility.php b/utility.php index c225e4d..b83f19d 100644 --- a/utility.php +++ b/utility.php @@ -3,6 +3,8 @@ * A set of utility helper functions */ +use Phroute\Phroute\Exception\HttpMethodNotAllowedException; +use Phroute\Phroute\Exception\HttpRouteNotFoundException; use Sakura\Config; use Sakura\Exceptions\ConfigValueNotFoundException; use Sakura\Net; @@ -52,6 +54,20 @@ function view($name, $vars = []) return Template::render($name); } +// Abort response +function abort($status = 200) +{ + http_response_code($status); + + switch ($status) { + case 403: + throw new HttpMethodNotAllowedException; + + case 404: + throw new HttpRouteNotFoundException; + } +} + function clean_string($string, $lower = false, $noSpecial = false, $replaceSpecial = '') { // Run common sanitisation function over string