Skip to content

Draft: Implement new loadConfig() and localConfigCached() methods#50

Draft
amulet1 wants to merge 1 commit intohorde:FRAMEWORK_6_0from
amulet1:load-config
Draft

Draft: Implement new loadConfig() and localConfigCached() methods#50
amulet1 wants to merge 1 commit intohorde:FRAMEWORK_6_0from
amulet1:load-config

Conversation

@amulet1
Copy link
Contributor

@amulet1 amulet1 commented Feb 22, 2026

DRAFT

Proposed initial code changes based on #49:

  • I did not remove anything yet, just added loadConfig() and loadConfigCached() both using internal static loadConfigInternal() method.
  • Both functions return variable value (if single variable was requested) or associative array with valuable values. This simplifies usage of the methods, as this is exactly what the existing cases are after.
  • If $vars = null, then all loaded variables are returned. This is mostly useful for caching (but we may not even need it - see below).
  • Output is no longer captured, but it also means it will be emitted on loading. I do not see places where it is used.
  • Note, I use a function (see $load_vars) that isolates loaded variables from all other variables, and therefore we only capture what is really loaded. Before compact was used to retrieve only the variables we are after, but the new code allows to retrieve (and possible cache) all the loaded variables.
  • I did not test it, but it is probably very close to the final version.
  • We still need to decide whether we want to use version with cache. In my opinion it is not needed, unless we start using long-term cache with auto-refresh (but this is somewhat beyond the current scope).

Typical usage:
Instead of $backends = $registry-> Horde::loadConfiguration('backends.php', 'backends', 'gollem');:
$backends = $registry->loadConfig('backends.php', 'backends');

Another example:

    public static function loadBackends()
    {
        global $registry;

        $config = $registry->loadConfigFile('backends.php', 'backends', 'ingo');
        if (empty($config->config['backends']) ||
            !is_array($config->config['backends'])) {
            throw new Ingo_Exception(_("No backends configured in backends.php"));
        }

        $out = [];
        foreach ($config->config['backends'] as $key => $val) {
            if (empty($val['disabled'])) {
                $out[$key] = $val;
            }
        }

        return $out;
    }

becomes

    public static function loadBackends()
    {
        global $registry;

        $backends = $registry->loadConfig('backends.php', 'backends', 'ingo');
        if (empty($backends) || !is_array($backends)) {
            throw new Ingo_Exception(_("No backends configured in backends.php"));
        }

        $out = [];
        foreach ($backends as $key => $val) {
            if (empty($val['disabled'])) {
                $out[$key] = $val;
            }
        }

        return $out;
    }

@amulet1
Copy link
Contributor Author

amulet1 commented Feb 22, 2026

@TDannhauer Please review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant