add support for legacy dependency config files

This commit is contained in:
Art4 2025-01-08 10:55:21 +00:00
parent 4fd8caaff7
commit dc6735eb51
5 changed files with 44 additions and 5 deletions

View file

@ -10,7 +10,7 @@ declare(strict_types=1);
namespace Friendica\Service\Addon; namespace Friendica\Service\Addon;
/** /**
* Interface to community with an addon. * Interface to communicate with an addon.
*/ */
interface Addon interface Addon
{ {

View file

@ -46,6 +46,7 @@ final class AddonManager
$dependencyRules = []; $dependencyRules = [];
foreach ($this->addons as $addon) { foreach ($this->addons as $addon) {
// @TODO At this point we can handle duplicate rules and handle possible conflicts
$dependencyRules = array_merge($dependencyRules, $addon->getProvidedDependencyRules()); $dependencyRules = array_merge($dependencyRules, $addon->getProvidedDependencyRules());
} }

View file

@ -38,6 +38,12 @@ final class LegacyAddonProxy implements Addon
public function getProvidedDependencyRules(): array public function getProvidedDependencyRules(): array
{ {
$fileName = $this->path . '/' . $this->name . '/static/dependencies.config.php';
if (is_file($fileName)) {
return include_once($fileName);
}
return []; return [];
} }

View file

@ -37,14 +37,18 @@ class LegacyAddonProxyTest extends TestCase
); );
} }
public function testGetProvidedDependencyRulesReturnsEmptyArray(): void public function testGetProvidedDependencyIncludesConfigFile(): void
{ {
$root = vfsStream::setup('addons', 0777, ['helloaddon' => []]); $root = vfsStream::setup('addons_4', 0777, ['helloaddon' => ['static' => []]]);
vfsStream::newFile('dependencies.config.php')
->at($root->getChild('helloaddon/static'))
->setContent('<?php return [\'name\' => []];');
$addon = new LegacyAddonProxy('helloaddon', $root->url()); $addon = new LegacyAddonProxy('helloaddon', $root->url());
$this->assertSame( $this->assertSame(
[], ['name' => []],
$addon->getProvidedDependencyRules() $addon->getProvidedDependencyRules()
); );
} }
@ -59,7 +63,6 @@ class LegacyAddonProxyTest extends TestCase
[], [],
$addon->getSubscribedEvents() $addon->getSubscribedEvents()
); );
} }
public function testInitAddonIncludesAddonFile(): void public function testInitAddonIncludesAddonFile(): void

View file

@ -0,0 +1,29 @@
<?php
/**
* @copyright Copyright (C) 2010-2024, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
return [
\Psr\Log\LoggerInterface::class => [
'instanceOf' => \Friendica\Core\Logger\Factory\Logger::class,
'call' => null,
],
];