aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/StudipControllerPropertiesTrait.php
diff options
context:
space:
mode:
authorPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
committerPhilipp Schüttlöffel <schuettloeffel@zqs.uni-hannover.de>2024-09-24 10:53:31 +0200
commit4459dd7917f4d1c34f40bb68f0e991e9c3d53e4c (patch)
tree5c07151ae61276d334e88f6309c30d439a85c12e /lib/classes/StudipControllerPropertiesTrait.php
parentda0022e5c1abbf9825ae76debaabdff7e8623bb4 (diff)
parent97a188592c679890a25c37ab78463add76a52ff7 (diff)
Merge branch 'main' into issue-3911issue-3911
Diffstat (limited to 'lib/classes/StudipControllerPropertiesTrait.php')
-rw-r--r--lib/classes/StudipControllerPropertiesTrait.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/classes/StudipControllerPropertiesTrait.php b/lib/classes/StudipControllerPropertiesTrait.php
new file mode 100644
index 0000000..4e906fa
--- /dev/null
+++ b/lib/classes/StudipControllerPropertiesTrait.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * This trait manages all variable assignments to the controller and templates.
+ *
+ * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
+ * @license GPL2 or any later version
+ * @since Stud.IP 5.2
+ */
+trait StudipControllerPropertiesTrait
+{
+ /**
+ * Stores the assigned variables.
+ * @var array
+ */
+ protected $_template_variables = [];
+
+ /**
+ * Returns whether a variable is set.
+ *
+ * @param string $offset
+ * @return bool
+ */
+ public function __isset(string $offset): bool
+ {
+ return isset($this->_template_variables[$offset]);
+ }
+
+ /**
+ * Stores a variable.
+ *
+ * @param string $offset
+ * @param mixed $value
+ */
+ public function __set(string $offset, $value): void
+ {
+ $this->_template_variables[$offset] = $value;
+ }
+
+ /**
+ * Returns a previously set variable.
+ *
+ * @param string $offset
+ * @return mixed
+ */
+ public function &__get(string $offset)
+ {
+ if (!isset($this->_template_variables[$offset])) {
+ $this->_template_variables[$offset] = null;
+ }
+ return $this->_template_variables[$offset];
+ }
+
+ /**
+ * Unsets a previously set variable
+ *
+ * @param string $offset
+ */
+ public function __unset(string $offset): void
+ {
+ unset($this->_template_variables[$offset]);
+ }
+
+ public function get_assigned_variables(): array
+ {
+ $variables = $this->_template_variables;
+ $variables['controller'] = $this;
+ return $variables;
+ }
+}