From 6454c1dee719d3fb45beb4edbe829d3ee8ce1a57 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 19:52:43 +0100 Subject: [PATCH 1/3] Don't ksort() on null --- src/Core/Addon.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Core/Addon.php b/src/Core/Addon.php index ef2289ca59..976b9799be 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -85,6 +85,11 @@ class Addon { $addons_admin = []; $addons = DI::config()->get('addons'); + + if (empty($addons)) { + return $addons_admin; + } + ksort($addons); foreach ($addons as $name => $data) { if (empty($data['admin'])) { From 9fb5b95b5ee0e9d269bc6982393966062b646509 Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 19:54:59 +0100 Subject: [PATCH 2/3] Fix other foreach() troubles at Addon.php --- src/Core/Addon.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 976b9799be..46ba0eec2b 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -196,6 +196,10 @@ class Addon { $addons = DI::config()->get('addons'); + if (empty($addons)) { + return; + } + foreach ($addons as $name => $data) { $addonname = Strings::sanitizeFilePathItem(trim($name)); $addon_file_path = 'addon/' . $addonname . '/' . $addonname . '.php'; @@ -318,6 +322,11 @@ class Addon { $visible_addons = []; $addons = DI::config()->get('addons'); + + if (empty($addons)) { + return $visible_addons; + } + foreach ($addons as $name => $data) { $visible_addons[] = $name; } From 6aaf1ea5d47dc8eedf2f7b852d7c246138d583cc Mon Sep 17 00:00:00 2001 From: Philipp Date: Sat, 7 Jan 2023 20:49:29 +0100 Subject: [PATCH 3/3] Fix addons problem more elegant --- src/Core/Addon.php | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Core/Addon.php b/src/Core/Addon.php index 46ba0eec2b..8d1a866915 100644 --- a/src/Core/Addon.php +++ b/src/Core/Addon.php @@ -51,7 +51,7 @@ class Addon * @return array * @throws \Exception */ - public static function getAvailableList() + public static function getAvailableList(): array { $addons = []; $files = glob('addon/*/'); @@ -81,14 +81,10 @@ class Addon * @return array * @throws \Exception */ - public static function getAdminList() + public static function getAdminList(): array { $addons_admin = []; - $addons = DI::config()->get('addons'); - - if (empty($addons)) { - return $addons_admin; - } + $addons = DI::config()->get('addons') ?? []; ksort($addons); foreach ($addons as $name => $data) { @@ -191,14 +187,12 @@ class Addon * reload all updated addons * * @return void + * @throws \Exception + * */ public static function reload() { - $addons = DI::config()->get('addons'); - - if (empty($addons)) { - return; - } + $addons = DI::config()->get('addons') ?? []; foreach ($addons as $name => $data) { $addonname = Strings::sanitizeFilePathItem(trim($name)); @@ -321,11 +315,7 @@ class Addon public static function getVisibleList(): array { $visible_addons = []; - $addons = DI::config()->get('addons'); - - if (empty($addons)) { - return $visible_addons; - } + $addons = DI::config()->get('addons') ?? []; foreach ($addons as $name => $data) { $visible_addons[] = $name;