Skip to content

Commit

Permalink
Same for themes + commands
Browse files Browse the repository at this point in the history
  • Loading branch information
slawkens committed Jan 26, 2024
1 parent cfdbc2a commit 511e10e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
3 changes: 2 additions & 1 deletion ma
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
37 changes: 32 additions & 5 deletions system/src/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ public static function getThemes()
}

$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()) {
Expand All @@ -137,6 +139,31 @@ public static function getThemes()
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();
Expand Down

0 comments on commit 511e10e

Please sign in to comment.