From 2c9af1c3afad3f3aedef073a7436d677283ea456 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sun, 16 Apr 2017 02:10:48 -0400 Subject: Add global state for page errors, warnings, etc. Added arrays to the global $_SCROTT variable to keep lists of page errors, warnings, and notices. Also added functions to globals.php for interacting with these arrays. --- app/class/globals.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/app/class/globals.php b/app/class/globals.php index 8bfa029..5a03da9 100644 --- a/app/class/globals.php +++ b/app/class/globals.php @@ -19,6 +19,19 @@ define("__VERSION__", "v0.0"); +/* + * These global variables are arrays of strings logged by Scrott business + * logic to report errors, warnings, or informational responses to the + * user in cases where an exception doesn't need to be thrown. + */ +define("ERROR", "errorlist"); +define("WARNING", "warninglist"); +define("NOTICE", "noticelist"); + +$_SCROTT[ERROR] = array(); +$_SCROTT[WARNING] = array(); +$_SCROTT[NOTICE] = array(); + /* * Get the application root path. This is an absolute path on the server. */ @@ -63,4 +76,31 @@ function require_https() : void redirect("https://" . $_SERVER['SERVER_NAME'] . ap()); } +/* + * Check for errors, warnings, or notices + */ +function isError(string $level) : bool +{ + global $_SCROTT; + return count($_SCROTT[$level]) > 0; +} + +/* + * Log an error, warning, or notice + */ +function logError(string $level, string $error) : void +{ + global $_SCROTT; + $_SCROTT[$level][] = $error; +} + +/* + * Get an array of all errors, warnings, or notices + */ +function getErrors(string $level) : array +{ + global $_SCROTT; + return $_SCROTT[$level]; +} + ?> -- cgit v1.2.3