summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/class/globals.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/class/globals.php b/app/class/globals.php
index 776fc35..8d27ae4 100644
--- a/app/class/globals.php
+++ b/app/class/globals.php
@@ -12,6 +12,8 @@
* For more information, please refer to UNLICENSE
*/
+require_once "class/obj.class.php";
+
/*
* This file defines various functions which exist in the global namespace.
* These are utility functions and constants for the Scrott application.
@@ -33,6 +35,14 @@ $_SCROTT[WARNING] = array();
$_SCROTT[NOTICE] = array();
/*
+ * The page object is the object our current request is primarily
+ * interested in. For example, when navigating to a pad web page by
+ * its guid, that pad is the page object. When viewing the dashboard,
+ * the current logged-in user is the page object.
+ */
+$_SCROTT['PAGE_OBJECT'] = NULL;
+
+/*
* Get the application root path. This is an absolute path on the server.
*/
function ar() : string
@@ -126,6 +136,29 @@ function getErrors(string $level) : array
}
/*
+ * Set the page object for the current request. This can only
+ * be called once per runtime.
+ */
+function setPageObj(obj $obj) : void
+{
+ global $_SCROTT;
+
+ if ($_SCROTT['PAGE_OBJECT'] !== NULL)
+ throw new Exception("Tried to establish page object context twice");
+
+ $_SCROTT['PAGE_OBJECT'] = $obj;
+}
+
+/*
+ * Get the page object for the current request.
+ */
+function getPageObj() : ?obj
+{
+ global $_SCROTT;
+ return $_SCROTT['PAGE_OBJECT'];
+}
+
+/*
* Save an uploaded file and impose some constraints on supplied
* data. Caller can optionally pass some strings by reference to
* be given the supplied file's original name and mime-type.