From: Philipp Holzer Date: Mon, 15 Jul 2019 19:14:13 +0000 (+0200) Subject: Allow nullable UID in PConfigCache X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f70271aa5d40ce48ec92f1c6ec652c6a977e588c;p=friendica.git Allow nullable UID in PConfigCache --- diff --git a/src/Core/Config/Cache/PConfigCache.php b/src/Core/Config/Cache/PConfigCache.php index d6b1c9b316..b0dd209cbf 100644 --- a/src/Core/Config/Cache/PConfigCache.php +++ b/src/Core/Config/Cache/PConfigCache.php @@ -36,6 +36,10 @@ class PConfigCache */ public function load($uid, array $config) { + if (!is_int($uid)) { + return; + } + $categories = array_keys($config); foreach ($categories as $category) { @@ -64,6 +68,10 @@ class PConfigCache */ public function get($uid, string $cat, string $key = null) { + if (!is_int($uid)) { + return null; + } + if (isset($this->config[$uid][$cat][$key])) { return $this->config[$uid][$cat][$key]; } elseif (!isset($key) && isset($this->config[$uid][$cat])) { @@ -87,6 +95,10 @@ class PConfigCache */ public function set($uid, string $cat, string $key, $value) { + if (!is_int($uid)) { + return false; + } + if (!isset($this->config[$uid]) || !is_array($this->config[$uid])) { $this->config[$uid] = []; } @@ -118,6 +130,10 @@ class PConfigCache */ public function delete($uid, string $cat, string $key) { + if (!is_int($uid)) { + return false; + } + if (isset($this->config[$uid][$cat][$key])) { unset($this->config[$uid][$cat][$key]); if (count($this->config[$uid][$cat]) == 0) { diff --git a/tests/src/Core/Config/Cache/PConfigCacheTest.php b/tests/src/Core/Config/Cache/PConfigCacheTest.php index 22beccf601..283a5bc6ab 100644 --- a/tests/src/Core/Config/Cache/PConfigCacheTest.php +++ b/tests/src/Core/Config/Cache/PConfigCacheTest.php @@ -255,4 +255,21 @@ class PConfigCacheTest extends MockedTest $this->assertNull($configCache->get(1, 'cat2', 'key2')); $this->assertNull($configCache->get(2, 'cat1', 'key1')); } + + /** + * Test when using an invalid UID + * @todo check it the clean way before using the config class + */ + public function testInvalidUid() + { + // bad UID! + $uid = null; + + $configCache = new PConfigCache(); + + $this->assertNull($configCache->get($uid, 'cat1', 'cat2')); + + $this->assertFalse($configCache->set($uid, 'cat1', 'key1', 'doesn\'t matter!')); + $this->assertFalse($configCache->delete($uid, 'cat1', 'key1')); + } }