summaryrefslogtreecommitdiffstats
path: root/app/class
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--app/class/table.class.php15
-rw-r--r--app/class/user.class.php1
2 files changed, 16 insertions, 0 deletions
diff --git a/app/class/table.class.php b/app/class/table.class.php
index 2759176..45be8c5 100644
--- a/app/class/table.class.php
+++ b/app/class/table.class.php
@@ -201,6 +201,21 @@ abstract class table
while (self::isGUID($guid));
return $guid;
}
+
+ /*
+ * Assert that this object is of the expected type in the database.
+ * Throw an exception if a type mismatch exists. Check will only
+ * be performed if guid and objtype are set on this object.
+ */
+ protected function expectType(string $objtype) : void
+ {
+ if (isset($this->guid) && isset($this->objtype))
+ {
+ if ($this->objtype != $objtype)
+ throw new Exception("Invalid object allocation. " . $this->guid . " is a " .
+ $this->objtype . ", not a " . $objtype . ".");
+ }
+ }
}
?>
diff --git a/app/class/user.class.php b/app/class/user.class.php
index 45fa5a5..7defa8f 100644
--- a/app/class/user.class.php
+++ b/app/class/user.class.php
@@ -38,6 +38,7 @@ class user extends agent
);
parent::__construct($guid);
+ $this->expectType("user");
}
/*