mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 09:19:22 +02:00
Make autoload of pages, commands and themes configurable
Not everyone might want them to autoload
This commit is contained in:
parent
47a19e85dd
commit
c1d4b4f80c
@ -40,5 +40,11 @@
|
||||
"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
|
||||
}
|
||||
}
|
||||
|
@ -89,6 +89,7 @@ class Plugins {
|
||||
}
|
||||
}
|
||||
|
||||
if (self::getAutoLoadOption($plugin, 'pages', true)) {
|
||||
//
|
||||
// Get all plugins/*/pages/*.php pages
|
||||
//
|
||||
@ -102,7 +103,9 @@ class Plugins {
|
||||
$duplicates[$name] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (self::getAutoLoadOption($plugin, 'pagesSubFolders', true)) {
|
||||
//
|
||||
// Get all plugins/*/pages/subFolder/*.php pages
|
||||
//
|
||||
@ -122,6 +125,7 @@ class Plugins {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usort($routes, function ($a, $b)
|
||||
{
|
||||
@ -158,6 +162,10 @@ class Plugins {
|
||||
|
||||
$themes = [];
|
||||
foreach(self::getAllPluginsJson() as $plugin) {
|
||||
if (!self::getAutoLoadOption($plugin, 'themes', true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pluginThemes = glob(PLUGINS . $plugin['filename'] . '/themes/*', GLOB_ONLYDIR);
|
||||
foreach ($pluginThemes as $path) {
|
||||
$path = str_replace(PLUGINS, 'plugins/', $path);
|
||||
@ -186,6 +194,10 @@ class Plugins {
|
||||
|
||||
$commands = [];
|
||||
foreach(self::getAllPluginsJson() as $plugin) {
|
||||
if (!self::getAutoLoadOption($plugin, 'commands', true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pluginCommands = glob(PLUGINS . $plugin['filename'] . '/commands/*.php');
|
||||
foreach ($pluginCommands as $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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user