Same for themes + commands

This commit is contained in:
slawkens 2024-01-27 00:56:45 +01:00
parent cfdbc2a8b2
commit 511e10e78b
2 changed files with 34 additions and 6 deletions

3
ma
View File

@ -11,6 +11,7 @@ if(!IS_CLI) {
require_once SYSTEM . 'functions.php';
require_once SYSTEM . 'init.php';
use MyAAC\Plugins;
use Symfony\Component\Console\Application;
$application = new Application();
@ -26,7 +27,7 @@ foreach ($commandsGlob as $item) {
$application->add(new ($commandPre . $name));
}
$pluginCommands = glob(PLUGINS . '*/commands/*.php');
$pluginCommands = Plugins::getCommands();
foreach ($pluginCommands as $item) {
$application->add(require $item);
}

View File

@ -122,12 +122,14 @@ class Plugins {
}
$themes = [];
$pluginThemes = glob(PLUGINS . '*/themes/*', GLOB_ONLYDIR);
foreach ($pluginThemes as $path) {
$path = str_replace(PLUGINS, 'plugins/', $path);
$name = pathinfo($path, PATHINFO_FILENAME);
foreach(self::getAllPluginsJson() as $plugin) {
$pluginThemes = glob(PLUGINS . $plugin['filename'] . '/themes/*', GLOB_ONLYDIR);
foreach ($pluginThemes as $path) {
$path = str_replace(PLUGINS, 'plugins/', $path);
$name = pathinfo($path, PATHINFO_FILENAME);
$themes[$name] = $path;
$themes[$name] = $path;
}
}
if ($cache->enabled()) {
@ -137,6 +139,31 @@ class Plugins {
return $themes;
}
public static function getCommands()
{
$cache = Cache::getInstance();
if ($cache->enabled()) {
$tmp = '';
if ($cache->fetch('plugins_commands', $tmp)) {
return unserialize($tmp);
}
}
$commands = [];
foreach(self::getAllPluginsJson() as $plugin) {
$pluginCommands = glob(PLUGINS . $plugin['filename'] . '/commands/*.php');
foreach ($pluginCommands as $path) {
$commands[] = $path;
}
}
if ($cache->enabled()) {
$cache->set('plugins_commands', serialize($commands), 600);
}
return $commands;
}
public static function getHooks()
{
$cache = Cache::getInstance();