mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-08 04:14:27 +02:00
Inline AddonLoader for strategies into StrategiesFileManager
This commit is contained in:
parent
694893e2bb
commit
203e9642d5
1 changed files with 63 additions and 8 deletions
|
@ -7,9 +7,15 @@
|
||||||
|
|
||||||
namespace Friendica\Core\Hooks\Util;
|
namespace Friendica\Core\Hooks\Util;
|
||||||
|
|
||||||
|
use Friendica\Core\Addon\AddonHelper;
|
||||||
use Friendica\Core\Addon\Capability\ICanLoadAddons;
|
use Friendica\Core\Addon\Capability\ICanLoadAddons;
|
||||||
|
use Friendica\Core\Addon\Exception\AddonInvalidConfigFileException;
|
||||||
|
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||||
use Friendica\Core\Hooks\Capability\ICanRegisterStrategies;
|
use Friendica\Core\Hooks\Capability\ICanRegisterStrategies;
|
||||||
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
use Friendica\Core\Hooks\Exceptions\HookConfigException;
|
||||||
|
use Friendica\Core\Logger\Factory\LoggerFactory;
|
||||||
|
use Friendica\Util\Strings;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manage all strategies.config.php files
|
* Manage all strategies.config.php files
|
||||||
|
@ -24,17 +30,15 @@ class StrategiesFileManager
|
||||||
const STATIC_DIR = 'static';
|
const STATIC_DIR = 'static';
|
||||||
const CONFIG_NAME = 'strategies';
|
const CONFIG_NAME = 'strategies';
|
||||||
|
|
||||||
/** @var ICanLoadAddons */
|
private AddonHelper $addonHelper;
|
||||||
protected $addonLoader;
|
protected array $config = [];
|
||||||
/** @var array */
|
|
||||||
protected $config = [];
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $basePath;
|
protected $basePath;
|
||||||
|
|
||||||
public function __construct(string $basePath, ICanLoadAddons $addonLoader)
|
public function __construct(string $basePath, AddonHelper $addonHelper)
|
||||||
{
|
{
|
||||||
$this->basePath = $basePath;
|
$this->basePath = $basePath;
|
||||||
$this->addonLoader = $addonLoader;
|
$this->addonHelper = $addonHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -69,7 +73,7 @@ class StrategiesFileManager
|
||||||
public function loadConfig()
|
public function loadConfig()
|
||||||
{
|
{
|
||||||
// load core hook config
|
// load core hook config
|
||||||
$configFile = $this->basePath . '/' . static::STATIC_DIR . '/' . static::CONFIG_NAME . '.config.php';
|
$configFile = $this->addonHelper->getAddonPath() . '/' . static::STATIC_DIR . '/' . static::CONFIG_NAME . '.config.php';
|
||||||
|
|
||||||
if (!file_exists($configFile)) {
|
if (!file_exists($configFile)) {
|
||||||
throw new HookConfigException(sprintf('config file %s does not exist.', $configFile));
|
throw new HookConfigException(sprintf('config file %s does not exist.', $configFile));
|
||||||
|
@ -84,6 +88,57 @@ class StrategiesFileManager
|
||||||
/**
|
/**
|
||||||
* @deprecated 2025.02 Providing strategies via addons is deprecated and will be removed in 5 months.
|
* @deprecated 2025.02 Providing strategies via addons is deprecated and will be removed in 5 months.
|
||||||
*/
|
*/
|
||||||
$this->config = array_merge_recursive($config, $this->addonLoader->getActiveAddonConfig(static::CONFIG_NAME));
|
$this->config = array_merge_recursive($config, $this->getActiveAddonConfig(static::CONFIG_NAME));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 2025.02 Providing strategies via addons is deprecated and will be removed in 5 months.
|
||||||
|
*/
|
||||||
|
private function getActiveAddonConfig(string $configName): array
|
||||||
|
{
|
||||||
|
$this->addonHelper->loadAddons();
|
||||||
|
|
||||||
|
$addons = $this->addonHelper->getEnabledAddons();
|
||||||
|
$returnConfig = [];
|
||||||
|
|
||||||
|
foreach ($addons as $addon) {
|
||||||
|
$addonName = Strings::sanitizeFilePathItem(trim($addon));
|
||||||
|
|
||||||
|
$configFile = $this->addonHelper->getAddonPath() . '/' . $addonName . '/' . static::STATIC_DIR . '/' . $configName . '.config.php';
|
||||||
|
|
||||||
|
if (!file_exists($configFile)) {
|
||||||
|
// Addon unmodified, skipping
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$config = include $configFile;
|
||||||
|
|
||||||
|
if (!is_array($config)) {
|
||||||
|
throw new AddonInvalidConfigFileException('Error loading config file ' . $configFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($configName === 'strategies') {
|
||||||
|
foreach ($config as $classname => $rule) {
|
||||||
|
if ($classname === LoggerInterface::class) {
|
||||||
|
@trigger_error(sprintf(
|
||||||
|
'Providing a strategy for `%s` is deprecated since 2025.02 and will stop working in 5 months, please provide an implementation for `%s` via `dependency.config.php` and remove the `strategies.config.php` file in the `%s` addon.',
|
||||||
|
$classname,
|
||||||
|
LoggerFactory::class,
|
||||||
|
$addonName,
|
||||||
|
), \E_USER_DEPRECATED);
|
||||||
|
} else {
|
||||||
|
@trigger_error(sprintf(
|
||||||
|
'Providing strategies for `%s` via addons is deprecated since 2025.02 and will stop working in 5 months, please stop using this and remove the `strategies.config.php` file in the `%s` addon.',
|
||||||
|
$classname,
|
||||||
|
$addonName,
|
||||||
|
), \E_USER_DEPRECATED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$returnConfig = array_merge_recursive($returnConfig, $config);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $returnConfig;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue