[ * 'enabled' => bool, // effective state * 'config_default' => bool, // env / config value * 'override' => bool|null, // SystemSetting override (null if none) * 'label' => string, * 'description' => string, * ], ...] */ public static function getAllModules(): array { $modules = Config::get('modules', []); $overrides = static::getOverrides(); $result = []; foreach ($modules as $key => $config) { if (!is_array($config)) { // Skips scalar entries like 'system_enabled'. continue; } $configDefault = (bool) ($config['enabled'] ?? true); $hasOverride = array_key_exists($key, $overrides); $override = $hasOverride ? (bool) $overrides[$key] : null; $result[$key] = [ 'enabled' => $hasOverride ? $override : $configDefault, 'config_default' => $configDefault, 'override' => $override, 'label' => $config['label'] ?? ucfirst($key), 'description' => $config['description'] ?? '', ]; } return $result; } /** * Get only the effective enabled/disabled states. * * @return array */ public static function getModuleStates(): array { $states = []; foreach (static::getAllModules() as $key => $info) { $states[$key] = (bool) $info['enabled']; } return $states; } /** * Read the override map from SystemSetting (cached). * * @return array */ protected static function getOverrides(): array { try { $value = SystemSetting::getValue(static::OVERRIDE_KEY); } catch (Throwable $e) { return []; } if (is_string($value) && $value !== '') { $decoded = json_decode($value, true); $value = is_array($decoded) ? $decoded : []; } if (!is_array($value)) { return []; } $out = []; foreach ($value as $k => $v) { $out[(string) $k] = filter_var($v, FILTER_VALIDATE_BOOLEAN); } return $out; } }