mirror of
https://github.com/friendica/friendica
synced 2025-02-21 20:46:48 +00:00
Create AddonHelper and proxy to check if addon is enabled
This commit is contained in:
parent
f1dfa63764
commit
91bd6089b5
5 changed files with 61 additions and 1 deletions
21
src/Core/Addon/AddonHelper.php
Normal file
21
src/Core/Addon/AddonHelper.php
Normal file
|
@ -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;
|
||||||
|
}
|
28
src/Core/Addon/AddonProxy.php
Normal file
28
src/Core/Addon/AddonProxy.php
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
namespace Friendica;
|
namespace Friendica;
|
||||||
|
|
||||||
use Dice\Dice;
|
use Dice\Dice;
|
||||||
|
use Friendica\Core\Addon\AddonHelper;
|
||||||
use Friendica\Core\Logger\Capability\ICheckLoggerSettings;
|
use Friendica\Core\Logger\Capability\ICheckLoggerSettings;
|
||||||
use Friendica\Core\Logger\LoggerManager;
|
use Friendica\Core\Logger\LoggerManager;
|
||||||
use Friendica\Core\Logger\Util\LoggerSettingsCheck;
|
use Friendica\Core\Logger\Util\LoggerSettingsCheck;
|
||||||
|
@ -280,6 +281,11 @@ abstract class DI
|
||||||
return self::$dice->create(Core\Storage\Repository\StorageManager::class);
|
return self::$dice->create(Core\Storage\Repository\StorageManager::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function addonHelper(): AddonHelper
|
||||||
|
{
|
||||||
|
return self::$dice->create(AddonHelper::class);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Friendica\Core\System
|
* @return \Friendica\Core\System
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -35,8 +35,10 @@ class Index extends BaseAdmin
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'toggle' :
|
case 'toggle' :
|
||||||
|
$addonHelper = DI::addonHelper();
|
||||||
|
|
||||||
$addon = $_GET['addon'] ?? '';
|
$addon = $_GET['addon'] ?? '';
|
||||||
if (Addon::isEnabled($addon)) {
|
if ($addonHelper->isEnabled($addon)) {
|
||||||
Addon::uninstall($addon);
|
Addon::uninstall($addon);
|
||||||
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s disabled.', $addon));
|
DI::sysmsg()->addInfo(DI::l10n()->t('Addon %s disabled.', $addon));
|
||||||
} elseif (Addon::install($addon)) {
|
} elseif (Addon::install($addon)) {
|
||||||
|
|
|
@ -42,6 +42,9 @@ return (function(string $basepath, array $getVars, array $serverVars, array $coo
|
||||||
[Dice::INSTANCE => Dice::SELF],
|
[Dice::INSTANCE => Dice::SELF],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
\Friendica\Core\Addon\AddonHelper::class => [
|
||||||
|
'instanceOf' => \Friendica\Core\Addon\AddonProxy::class,
|
||||||
|
],
|
||||||
\Friendica\Util\BasePath::class => [
|
\Friendica\Util\BasePath::class => [
|
||||||
'constructParams' => [
|
'constructParams' => [
|
||||||
$basepath,
|
$basepath,
|
||||||
|
|
Loading…
Add table
Reference in a new issue