]> git.mxchange.org Git - friendica.git/commitdiff
Create AddonHelper and proxy to check if addon is enabled
authorArt4 <art4@wlabs.de>
Sat, 1 Feb 2025 21:58:59 +0000 (21:58 +0000)
committerArt4 <art4@wlabs.de>
Sat, 1 Feb 2025 21:58:59 +0000 (21:58 +0000)
src/Core/Addon/AddonHelper.php [new file with mode: 0644]
src/Core/Addon/AddonProxy.php [new file with mode: 0644]
src/DI.php
src/Module/Admin/Addons/Index.php
static/dependencies.config.php

diff --git a/src/Core/Addon/AddonHelper.php b/src/Core/Addon/AddonHelper.php
new file mode 100644 (file)
index 0000000..7b65da6
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Core\Addon;
+
+/**
+ * Some functions to handle addons
+ */
+interface AddonHelper
+{
+       /**
+        * Checks if the provided addon is enabled
+        */
+       public function isEnabled(string $addonId): bool;
+}
diff --git a/src/Core/Addon/AddonProxy.php b/src/Core/Addon/AddonProxy.php
new file mode 100644 (file)
index 0000000..9d1b1b0
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+
+// Copyright (C) 2010-2024, the Friendica project
+// SPDX-FileCopyrightText: 2010-2024 the Friendica project
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+declare(strict_types=1);
+
+namespace Friendica\Core\Addon;
+
+use Friendica\Core\Addon;
+
+/**
+ * Proxy to the Addon class
+ *
+ * @internal
+ */
+final class AddonProxy implements AddonHelper
+{
+       /**
+        * Checks if the provided addon is enabled
+        */
+       public function isEnabled(string $addonId): bool
+       {
+               return Addon::isEnabled($addonId);
+       }
+}
index c9c973f722a387c392ce3b5656d7d6ebb9762d5c..8e279228295ad878193d496bf06f98b31af3eda4 100644 (file)
@@ -8,6 +8,7 @@
 namespace Friendica;
 
 use Dice\Dice;
+use Friendica\Core\Addon\AddonHelper;
 use Friendica\Core\Logger\Capability\ICheckLoggerSettings;
 use Friendica\Core\Logger\LoggerManager;
 use Friendica\Core\Logger\Util\LoggerSettingsCheck;
@@ -280,6 +281,11 @@ abstract class DI
                return self::$dice->create(Core\Storage\Repository\StorageManager::class);
        }
 
+       public static function addonHelper(): AddonHelper
+       {
+               return self::$dice->create(AddonHelper::class);
+       }
+
        /**
         * @return \Friendica\Core\System
         */
index 8ebf1f918d178306cf8b23e2dabce621d9a4a3bb..c39ac0999a8b87ac687c08e3ad1d6d7da1cd8bb9 100644 (file)
@@ -35,8 +35,10 @@ class Index extends BaseAdmin
                                        break;
 
                                case 'toggle' :
+                                       $addonHelper = DI::addonHelper();
+
                                        $addon = $_GET['addon'] ?? '';
-                                       if (Addon::isEnabled($addon)) {
+                                       if ($addonHelper->isEnabled($addon)) {
                                                Addon::uninstall($addon);
                                                DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s disabled.', $addon));
                                        } elseif (Addon::install($addon)) {
index f1c2f4e52e3d2648bda150a4a5b5bd9f0f576db1..c41200cb4eeed0ccfef08cece724d1f422f79972 100644 (file)
@@ -42,6 +42,9 @@ return (function(string $basepath, array $getVars, array $serverVars, array $coo
                                [Dice::INSTANCE => Dice::SELF],
                        ],
                ],
+               \Friendica\Core\Addon\AddonHelper::class => [
+                       'instanceOf' => \Friendica\Core\Addon\AddonProxy::class,
+               ],
                \Friendica\Util\BasePath::class => [
                        'constructParams' => [
                                $basepath,