mirror of
https://code.castopod.org/adaures/castopod
synced 2025-04-23 01:01:20 +00:00
52 lines
1.3 KiB
PHP
52 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use Modules\Plugins\Core\Plugins;
|
|
|
|
if (! function_exists('plugins')) {
|
|
function plugins(): Plugins
|
|
{
|
|
return service('plugins');
|
|
}
|
|
}
|
|
|
|
if (! function_exists('get_plugin_option')) {
|
|
/**
|
|
* @param ?array{'podcast'|'episode',int} $additionalContext
|
|
*/
|
|
function get_plugin_option(string $pluginKey, string $option, array $additionalContext = null): mixed
|
|
{
|
|
$key = sprintf('Plugins.%s', $option);
|
|
$context = sprintf('plugin:%s', $pluginKey);
|
|
|
|
if ($additionalContext !== null) {
|
|
$context .= sprintf('+%s:%d', ...$additionalContext);
|
|
}
|
|
|
|
return setting()->get($key, $context);
|
|
}
|
|
}
|
|
|
|
if (! function_exists('set_plugin_option')) {
|
|
/**
|
|
* @param ?array{'podcast'|'episode',int} $additionalContext
|
|
*/
|
|
function set_plugin_option(
|
|
string $pluginKey,
|
|
string $option,
|
|
mixed $value = null,
|
|
array $additionalContext = null
|
|
): void {
|
|
$key = sprintf('Plugins.%s', $option);
|
|
$context = sprintf('plugin:%s', $pluginKey);
|
|
|
|
if ($additionalContext !== null) {
|
|
$context .= sprintf('+%s:%d', ...$additionalContext);
|
|
}
|
|
|
|
setting()
|
|
->set($key, $value, $context);
|
|
}
|
|
}
|