Skip to content

loadConfiguration and loadConfigFile #49

@amulet1

Description

@amulet1

We have (A) Horde_Deprecated::loadConfiguration() which is still used in several places. Internally it is rewritten to call (B) Horde_Registry::loadConfigFile(), which caches and returns instance of (C) Horde_Registry_Loadconfig class. Also Horde_Registry_Loadconfig is called directly in a few places.

I see several issues:

  1. Why do we still use the supposedly deprecated loadConfiguration()?
  2. It is questionable that cache in Horde_Registry::loadConfigFile() really helps with anything. If we indeed load same file multiple times in the same app during a single request, than maybe something is wrong with the app. Additionally, the result depends on the $vars parameter, however the cache key disregards this, and if a call is ever made for the same config file but with different $vars parameter, it will return the previously cached value (wrong!).
  3. The main reason Horde_Registry_Loadconfig instance is returned is to be able to access its output and config properties. Its constructor uses $registry global, which could be avoided if it was implemented as a method in Horde_Registry class.
  4. I looked at all places where the 3 methods are used across all Horde applications. As far as I can see, output property (which holds captured output produced by loaded file) is never used. I am not sure if there are some 3rd party applications that somehow rely on it, but clearly there are simpler ways to capture output. Places that use (B) or (C) use config property value - which is what the deprecated Horde_Deprecated::loadConfiguration() method already did.

In nearly all cases (when a single variable was used) the "deprecated" code looked like
(D) $result = Horde::loadConfiguration($config_file, $var_name, $app);

The equivalent newer code is
(E) $result = $registry->loadConfigFile($config_file, $var_name, $app)->config[$var_name];

Suggestions:
Let's create a new (non-static!) method Horde_Registry:loadConfig which would generally replicate (A) behavior, but without any extra classes or methods involved, and without output being captured.

We have to decide if caching is needed (probably not, or at least it should be optional). If we need it, then at least it should be done smarter - e.g. cache values in Redis, and auto-refresh if file(s) last-modified timestamp changes.

We then switch to using this method instead of (A), (B) and (C) and remove the unused old code.

With this suggestion a typical call equivalent to (D) or (E) would be like this:
(F) $result = $registry->loadConfig($config_file, $var_name, $app);

Overall (F) is cleaner and simpler to use.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions