Make autoload of pages, commands and themes configurable

Not everyone might want them to autoload
This commit is contained in:
slawkens 2024-06-13 14:36:18 +02:00
parent 47a19e85dd
commit c1d4b4f80c
2 changed files with 60 additions and 25 deletions

View File

@ -40,5 +40,11 @@
"redirect_to": "account/manage" "redirect_to": "account/manage"
} }
}, },
"settings": "plugins/your-plugin-folder/settings.php" "settings": "plugins/your-plugin-folder/settings.php",
"autoload": {
"pages": true,
"pagesSubFolders": false,
"commands": true,
"themes": true
}
} }

View File

@ -89,6 +89,7 @@ class Plugins {
} }
} }
if (self::getAutoLoadOption($plugin, 'pages', true)) {
// //
// Get all plugins/*/pages/*.php pages // Get all plugins/*/pages/*.php pages
// //
@ -102,7 +103,9 @@ class Plugins {
$duplicates[$name] = true; $duplicates[$name] = true;
} }
} }
}
if (self::getAutoLoadOption($plugin, 'pagesSubFolders', true)) {
// //
// Get all plugins/*/pages/subFolder/*.php pages // Get all plugins/*/pages/subFolder/*.php pages
// //
@ -122,6 +125,7 @@ class Plugins {
} }
} }
} }
}
usort($routes, function ($a, $b) usort($routes, function ($a, $b)
{ {
@ -158,6 +162,10 @@ class Plugins {
$themes = []; $themes = [];
foreach(self::getAllPluginsJson() as $plugin) { foreach(self::getAllPluginsJson() as $plugin) {
if (!self::getAutoLoadOption($plugin, 'themes', true)) {
continue;
}
$pluginThemes = glob(PLUGINS . $plugin['filename'] . '/themes/*', GLOB_ONLYDIR); $pluginThemes = glob(PLUGINS . $plugin['filename'] . '/themes/*', GLOB_ONLYDIR);
foreach ($pluginThemes as $path) { foreach ($pluginThemes as $path) {
$path = str_replace(PLUGINS, 'plugins/', $path); $path = str_replace(PLUGINS, 'plugins/', $path);
@ -186,6 +194,10 @@ class Plugins {
$commands = []; $commands = [];
foreach(self::getAllPluginsJson() as $plugin) { foreach(self::getAllPluginsJson() as $plugin) {
if (!self::getAutoLoadOption($plugin, 'commands', true)) {
continue;
}
$pluginCommands = glob(PLUGINS . $plugin['filename'] . '/commands/*.php'); $pluginCommands = glob(PLUGINS . $plugin['filename'] . '/commands/*.php');
foreach ($pluginCommands as $path) { foreach ($pluginCommands as $path) {
$commands[] = $path; $commands[] = $path;
@ -792,4 +804,21 @@ class Plugins {
} }
} }
} }
private static function getAutoLoadOption(array $plugin, string $optionName, bool $default = true)
{
if (isset($plugin['autoload'])) {
$autoload = $plugin['autoload'];
if (is_array($autoload)) {
if (isset($autoload[$optionName])) {
return getBoolean($autoload[$optionName]);
}
}
else if (is_bool($autoload)) {
return $autoload;
}
}
return $default;
}
} }