diff --git a/app/Helpers/rss_helper.php b/app/Helpers/rss_helper.php index 90f9ee717b99f96a9ecf409dd477f319cfe862ff..bd13598e10a8c9e7f77922d87712220e2c30033f 100644 --- a/app/Helpers/rss_helper.php +++ b/app/Helpers/rss_helper.php @@ -31,6 +31,8 @@ if (! function_exists('get_rss_feed')) { Subscription $subscription = null, string $token = null ): string { + $plugins = service('plugins'); + $episodes = $podcast->episodes; $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('docs', 'https://cyber.harvard.edu/rss/rss.html'); + $plugins->runHook('setChannelTag', [$podcast, $channel]); + if ($podcast->guid === '') { // FIXME: guid shouldn't be empty here as it should be filled upon Podcast creation $uuid = service('uuid'); diff --git a/modules/Plugins/Plugins.php b/modules/Plugins/Plugins.php index cebc49fabee52b3eb7f48dbf915e2dadb3f1804f..9dc5bd57c61f509417b69fd1bd8552c77271a078 100644 --- a/modules/Plugins/Plugins.php +++ b/modules/Plugins/Plugins.php @@ -9,18 +9,54 @@ class Plugins /** * @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> */ - 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; + } } }