[dev] Empty <configsection>'s

Jon Parise jon at horde.org
Sun Feb 22 18:56:39 PST 2004


I ran into an interesting problem with Horde_Config and empty
<configsection>'s today.  I don't know this code too well so I'm
soliciting possible solutions here.

Take the case of the 'syslog' log handler.  Its entry in conf.xml
looks like this:

      <case name="syslog" desc="Syslog">
       <configphp name="name" quote="false" desc="Syslog facility to use"/>
      </case>

Note that, unlike the other log handlers, it takes no parameters.
Unfortunately, we have a handful of code (in Horde and in the Log
package) that assumes at we at least pass an empty array as the
factory's $params argument.  Right now, though, the Horde_Config code
won't write any '$conf['log']['params']' entries if 'syslog' is
selected.

I started by making the "empty params" requirement explicit by
changing the 'syslog' entry in conf.xml to this:

      <case name="syslog" desc="Syslog">
       <configphp name="name" quote="false" desc="Syslog facility to use"/>
       <configsection name="params">
       </configsection>
      </case>

This still won't output any '$conf['log']['params']' entries, however.

Next, I modified Horde/Config.php thusly:

--- Config.php  2 Feb 2004 22:50:36 -0000       1.56
+++ Config.php  23 Feb 2004 02:49:18 -0000
@@ -260,6 +260,8 @@
                     }
                     break;
                 }
+            } elseif (is_array($configitem) && empty($configitem)) {
+                $value = 'array()';
             } else {
                 $this->_generatePHPConfig($configitem, $prefixedname, $formvars);
             }

This produced the desired result ("$conf['log']['params'] = array();"
in the resulting output), but I'm not sure this fits with the spirit
of the surrounding code.

Alternate solutions:

1.  Introduce a <configparams> entity.  It will always write an
    'array()' entry to the configuration output.  This will generally
    be redundant when real parameters are also written, but it's
    technically correct and will always work.

2.  Assume all <configsection> sections map directly to an array of
    subelements.  Give them a '_type' of 'array' and add the
    associated machinery to Horde_Config.

    (This is a more generalized version of solution 1.)

Opinions, please.

-- 
Jon Parise (jon at horde.org) :: The Horde Project (http://horde.org/)


More information about the dev mailing list