mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-10 06:54:26 +02:00
Create Addon class, that calls Addon Bootstrap
This commit is contained in:
parent
a6a0af0670
commit
b3bc5981ea
4 changed files with 74 additions and 3 deletions
32
src/Addon/Addon.php
Normal file
32
src/Addon/Addon.php
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?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\Addon;
|
||||
|
||||
use Friendica\Addon\Event\AddonStartEvent;
|
||||
|
||||
/**
|
||||
* Proxy object for an addon.
|
||||
*/
|
||||
final class Addon
|
||||
{
|
||||
private AddonBootstrap $bootstrap;
|
||||
|
||||
public function __construct(AddonBootstrap $bootstrap)
|
||||
{
|
||||
$this->bootstrap = $bootstrap;
|
||||
}
|
||||
|
||||
public function initAddon(): void
|
||||
{
|
||||
$event = new AddonStartEvent();
|
||||
|
||||
$this->bootstrap->initAddon($event);
|
||||
}
|
||||
}
|
|
@ -25,5 +25,5 @@ interface AddonBootstrap extends StaticEventSubscriber
|
|||
/**
|
||||
* Init of the addon.
|
||||
*/
|
||||
public static function initAddon(AddonStartEvent $event): void;
|
||||
public function initAddon(AddonStartEvent $event): void;
|
||||
}
|
||||
|
|
38
tests/Unit/Addon/AddonTest.php
Normal file
38
tests/Unit/Addon/AddonTest.php
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?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\Test\Unit\Addon;
|
||||
|
||||
use Friendica\Addon\Addon;
|
||||
use Friendica\Addon\AddonBootstrap;
|
||||
use Friendica\Addon\Event\AddonStartEvent;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AddonTest extends TestCase
|
||||
{
|
||||
public function testCreateWithAddonBootstrap(): void
|
||||
{
|
||||
$bootstrap = $this->createMock(AddonBootstrap::class);
|
||||
|
||||
$addon = new Addon($bootstrap);
|
||||
|
||||
$this->assertInstanceOf(Addon::class, $addon);
|
||||
}
|
||||
|
||||
public function testInitAddonCallsBootstrap(): void
|
||||
{
|
||||
$bootstrap = $this->createMock(AddonBootstrap::class);
|
||||
$bootstrap->expects($this->once())->method('initAddon')->willReturnCallback(function($event) {
|
||||
$this->assertInstanceOf(AddonStartEvent::class, $event);
|
||||
});
|
||||
|
||||
$addon = new Addon($bootstrap);
|
||||
$addon->initAddon();
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace FriendicaAddons\HelloAddon;
|
||||
|
||||
use Friendica\Addon\AddonBootstrap;
|
||||
use Friendica\Addon\Event\AddonInstallEvent;
|
||||
use Friendica\Addon\Event\AddonStartEvent;
|
||||
use Friendica\Addon\Event\AddonUninstallEvent;
|
||||
|
@ -23,7 +24,7 @@ use Friendica\Event\ProvideLoggerEvent;
|
|||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
class HelloAddon implements \Friendica\Addon\AddonBootstrap
|
||||
class HelloAddon implements AddonBootstrap
|
||||
{
|
||||
/** @var LoggerInterface */
|
||||
private static $logger;
|
||||
|
@ -50,7 +51,7 @@ class HelloAddon implements \Friendica\Addon\AddonBootstrap
|
|||
];
|
||||
}
|
||||
|
||||
public static function initAddon(AddonStartEvent $event): void
|
||||
public function initAddon(AddonStartEvent $event): void
|
||||
{
|
||||
// $dependencies containts an array of services defined in getRequiredDependencies().
|
||||
// The keys are the FQCN of the services.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue