mirror of
https://git.sekbaer.de/Friendica/friendica.git
synced 2025-06-07 15:54:26 +02:00
Implement loading addons in AddonManagerHelper
This commit is contained in:
parent
e2a2cf5d6e
commit
93a171765a
2 changed files with 38 additions and 3 deletions
|
@ -9,6 +9,7 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Friendica\Core\Addon;
|
namespace Friendica\Core\Addon;
|
||||||
|
|
||||||
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,16 +21,23 @@ final class AddonManagerHelper implements AddonHelper
|
||||||
{
|
{
|
||||||
private string $addonPath;
|
private string $addonPath;
|
||||||
|
|
||||||
|
private IManageConfigValues $config;
|
||||||
|
|
||||||
private Profiler $profiler;
|
private Profiler $profiler;
|
||||||
|
|
||||||
|
/** @var string[] */
|
||||||
|
private array $addons = [];
|
||||||
|
|
||||||
/** @deprecated */
|
/** @deprecated */
|
||||||
private AddonHelper $proxy;
|
private AddonHelper $proxy;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
string $addonPath,
|
string $addonPath,
|
||||||
|
IManageConfigValues $config,
|
||||||
Profiler $profiler
|
Profiler $profiler
|
||||||
) {
|
) {
|
||||||
$this->addonPath = $addonPath;
|
$this->addonPath = $addonPath;
|
||||||
|
$this->config = $config;
|
||||||
$this->profiler = $profiler;
|
$this->profiler = $profiler;
|
||||||
|
|
||||||
$this->proxy = new AddonProxy($addonPath);
|
$this->proxy = new AddonProxy($addonPath);
|
||||||
|
@ -86,7 +94,7 @@ final class AddonManagerHelper implements AddonHelper
|
||||||
*/
|
*/
|
||||||
public function loadAddons(): void
|
public function loadAddons(): void
|
||||||
{
|
{
|
||||||
$this->proxy->loadAddons();
|
$this->addons = array_keys(array_filter($this->config->get('addons') ?? []));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -125,7 +133,7 @@ final class AddonManagerHelper implements AddonHelper
|
||||||
*/
|
*/
|
||||||
public function isAddonEnabled(string $addonId): bool
|
public function isAddonEnabled(string $addonId): bool
|
||||||
{
|
{
|
||||||
return $this->proxy->isAddonEnabled($addonId);
|
return in_array($addonId, $this->addons);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,7 +143,7 @@ final class AddonManagerHelper implements AddonHelper
|
||||||
*/
|
*/
|
||||||
public function getEnabledAddons(): array
|
public function getEnabledAddons(): array
|
||||||
{
|
{
|
||||||
return $this->proxy->getEnabledAddons();
|
return $this->addons;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -11,6 +11,7 @@ namespace Friendica\Test\Unit\Core\Addon;
|
||||||
|
|
||||||
use Friendica\Core\Addon\AddonInfo;
|
use Friendica\Core\Addon\AddonInfo;
|
||||||
use Friendica\Core\Addon\AddonManagerHelper;
|
use Friendica\Core\Addon\AddonManagerHelper;
|
||||||
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Util\Profiler;
|
use Friendica\Util\Profiler;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ class AddonManagerHelperTest extends TestCase
|
||||||
{
|
{
|
||||||
$addonManagerHelper = new AddonManagerHelper(
|
$addonManagerHelper = new AddonManagerHelper(
|
||||||
__DIR__ . '/../../../Util/addons',
|
__DIR__ . '/../../../Util/addons',
|
||||||
|
$this->createStub(IManageConfigValues::class),
|
||||||
$this->createStub(Profiler::class)
|
$this->createStub(Profiler::class)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -29,4 +31,29 @@ class AddonManagerHelperTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals('Hello Addon', $info->getName());
|
$this->assertEquals('Hello Addon', $info->getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEnabledAddons(): void
|
||||||
|
{
|
||||||
|
$config = $this->createStub(IManageConfigValues::class);
|
||||||
|
$config->method('get')->willReturn([
|
||||||
|
'helloaddon' => [
|
||||||
|
'last_update' => 1738760499,
|
||||||
|
'admin' => false,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$addonManagerHelper = new AddonManagerHelper(
|
||||||
|
__DIR__ . '/../../../Util/addons',
|
||||||
|
$config,
|
||||||
|
$this->createStub(Profiler::class)
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSame([], $addonManagerHelper->getEnabledAddons());
|
||||||
|
$this->assertFalse($addonManagerHelper->isAddonEnabled('helloaddon'));
|
||||||
|
|
||||||
|
$addonManagerHelper->loadAddons();
|
||||||
|
|
||||||
|
$this->assertSame(['helloaddon'], $addonManagerHelper->getEnabledAddons());
|
||||||
|
$this->assertTrue($addonManagerHelper->isAddonEnabled('helloaddon'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue