From 7a58c9da8ffac9b0832a047fe4ef1b93618179f0 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 22 Jul 2018 14:01:07 +0000 Subject: [PATCH] Enhanced ttConfigHelper class a bit. --- WEB-INF/lib/ttConfigHelper.class.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/WEB-INF/lib/ttConfigHelper.class.php b/WEB-INF/lib/ttConfigHelper.class.php index b33734c8..13a2a851 100644 --- a/WEB-INF/lib/ttConfigHelper.class.php +++ b/WEB-INF/lib/ttConfigHelper.class.php @@ -47,6 +47,28 @@ class ttConfigHelper { return in_array($name, $this->config_array); } + // setDefinedValue either sets or deletes a defined value identified by name. + function setDefinedValue($name, $set = true) { + if ($set) { + // Setting part. + if (!$this->getDefinedValue($name)) { + $this->config_array[] = $name; + $this->config = implode(',', $this->config_array); + return; + } + + } else { + // Deleting part. + foreach ($this->config_array as $key => $value) { + if ($value === $name) { + unset($this->config_array[$key]); + $this->config = implode(',', $this->config_array); + return; + } + } + } + } + // The getIntValue parses an integer value from the source config string. function getIntValue($name) { $name_with_colon = $name.':'; @@ -73,12 +95,11 @@ class ttConfigHelper { foreach ($this->config_array as $key => $unparsed_value) { if (substr($unparsed_value, 0, $len) === $name_with_colon) { // Found an already existing value. - // Remove value if our new value is NULL. if ($value !== null) { // Replace value. $this->config_array[$key] = $name.':'.$value; } else { - // Remove value. + // Remove value if our new value is NULL. unset($this->config_array[$key]); } $this->config = implode(',', $this->config_array); -- 2.20.1