mirror of
https://code.castopod.org/adaures/castopod
synced 2025-05-30 05:52:02 +00:00
feat(plugins): load plugins using file locator service
This commit is contained in:
parent
5293752bb5
commit
2f517fde47
@ -31,6 +31,8 @@ if (! function_exists('get_rss_feed')) {
|
|||||||
Subscription $subscription = null,
|
Subscription $subscription = null,
|
||||||
string $token = null
|
string $token = null
|
||||||
): string {
|
): string {
|
||||||
|
$plugins = service('plugins');
|
||||||
|
|
||||||
$episodes = $podcast->episodes;
|
$episodes = $podcast->episodes;
|
||||||
|
|
||||||
$itunesNamespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
|
$itunesNamespace = 'http://www.itunes.com/dtds/podcast-1.0.dtd';
|
||||||
@ -69,6 +71,8 @@ if (! function_exists('get_rss_feed')) {
|
|||||||
$channel->addChild('generator', 'Castopod - https://castopod.org/');
|
$channel->addChild('generator', 'Castopod - https://castopod.org/');
|
||||||
$channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html');
|
$channel->addChild('docs', 'https://cyber.harvard.edu/rss/rss.html');
|
||||||
|
|
||||||
|
$plugins->runHook('setChannelTag', [$podcast, $channel]);
|
||||||
|
|
||||||
if ($podcast->guid === '') {
|
if ($podcast->guid === '') {
|
||||||
// FIXME: guid shouldn't be empty here as it should be filled upon Podcast creation
|
// FIXME: guid shouldn't be empty here as it should be filled upon Podcast creation
|
||||||
$uuid = service('uuid');
|
$uuid = service('uuid');
|
||||||
|
@ -9,18 +9,54 @@ class Plugins
|
|||||||
/**
|
/**
|
||||||
* @var array<PluginInterface>
|
* @var array<PluginInterface>
|
||||||
*/
|
*/
|
||||||
protected array $installed = [];
|
protected static array $plugins = [];
|
||||||
|
|
||||||
public function registerPlugin(PluginInterface $plugin): void
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->installed[] = $plugin;
|
$this->registerPlugins();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<PluginInterface>
|
* @return array<PluginInterface>
|
||||||
*/
|
*/
|
||||||
public function getInstalled(): array
|
public function getPlugins(): array
|
||||||
{
|
{
|
||||||
return $this->installed;
|
return $this->plugins;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<mixed> $parameters
|
||||||
|
*/
|
||||||
|
public function runHook(string $name, array $parameters): void
|
||||||
|
{
|
||||||
|
dd(static::$plugins);
|
||||||
|
// only run active plugins' hooks
|
||||||
|
foreach (static::$plugins as $plugin) {
|
||||||
|
$plugin->{$name}(...$parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function registerPlugins(): void
|
||||||
|
{
|
||||||
|
$locator = service('locator');
|
||||||
|
$pluginsFiles = $locator->search('HelloWorld/Plugin.php');
|
||||||
|
|
||||||
|
// dd($pluginsFiles);
|
||||||
|
|
||||||
|
foreach ($pluginsFiles as $file) {
|
||||||
|
$className = $locator->findQualifiedNameFromPath($file);
|
||||||
|
|
||||||
|
dd($file);
|
||||||
|
if ($className === false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$plugin = new $className();
|
||||||
|
if (! $plugin instanceof PluginInterface) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
static::$plugins[] = $plugin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user