Make Horde_Config_Form autoloadable
authorMichael M Slusarz <slusarz@curecanti.org>
Sun, 31 Jan 2010 03:49:53 +0000 (20:49 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Sun, 31 Jan 2010 05:05:09 +0000 (22:05 -0700)
framework/Core/lib/Horde/Config.php
framework/Core/lib/Horde/Config/Form.php [new file with mode: 0644]
framework/Core/package.xml
horde/admin/setup/config.php

index f09d608..f24d444 100644 (file)
@@ -1567,149 +1567,3 @@ class Horde_Config
     }
 
 }
-
-/**
- * A Horde_Form:: form that implements a user interface for the config
- * system.
- *
- * @author  Chuck Hagenbuch <chuck@horde.org>
- * @package Core
- */
-class ConfigForm extends Horde_Form
-{
-    /**
-     * Don't use form tokens for the configuration form - while
-     * generating configuration info, things like the Token system
-     * might not work correctly. This saves some headaches.
-     *
-     * @var boolean
-     */
-    protected $_useFormToken = false;
-
-    /**
-     * Contains the Horde_Config object that this form represents.
-     *
-     * @var Horde_Config
-     */
-    protected $_xmlConfig;
-
-    /**
-     * Contains the Horde_Variables object of this form.
-     *
-     * @var Horde_Variables
-     */
-    protected $_vars;
-
-    /**
-     * Constructor.
-     *
-     * @param Horde_Variables &$vars  The variables object of this form.
-     * @param string $app             The name of the application that this
-     *                                configuration form is for.
-     */
-    public function __construct(&$vars, $app)
-    {
-        parent::__construct($vars);
-
-        $this->_xmlConfig = new Horde_Config($app);
-        $this->_vars = &$vars;
-        $config = $this->_xmlConfig->readXMLConfig();
-        $this->addHidden('', 'app', 'text', true);
-        $this->_buildVariables($config);
-    }
-
-    /**
-     * Builds the form based on the specified level of the configuration tree.
-     *
-     * @param array $config   The portion of the configuration tree for that
-     *                        the form fields should be created.
-     * @param string $prefix  A string representing the current position
-     *                        inside the configuration tree.
-     */
-    protected function _buildVariables($config, $prefix = '')
-    {
-        if (!is_array($config)) {
-            return;
-        }
-
-        foreach ($config as $name => $configitem) {
-            $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name;
-            $varname = str_replace('|', '__', $prefixedname);
-            if ($configitem == 'placeholder') {
-                continue;
-            } elseif (isset($configitem['tab'])) {
-                $this->setSection($configitem['tab'], $configitem['desc']);
-            } elseif (isset($configitem['switch'])) {
-                $selected = $this->_vars->getExists($varname, $wasset);
-                $var_params = array();
-                $select_option = true;
-                if (is_bool($configitem['default'])) {
-                    $configitem['default'] = $configitem['default'] ? 'true' : 'false';
-                }
-                foreach ($configitem['switch'] as $option => $case) {
-                    $var_params[$option] = $case['desc'];
-                    if ($option == $configitem['default']) {
-                        $select_option = false;
-                        if (!$wasset) {
-                            $selected = $option;
-                        }
-                    }
-                }
-
-                $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
-                $desc = $configitem['desc'];
-
-                $v = &$this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option));
-                if (array_key_exists('default', $configitem)) {
-                    $v->setDefault($configitem['default']);
-                }
-                if (!empty($configitem['is_default'])) {
-                    $v->_new = true;
-                }
-                $v_action = Horde_Form_Action::factory('reload');
-                $v->setAction($v_action);
-                if (isset($selected) && isset($configitem['switch'][$selected])) {
-                    $this->_buildVariables($configitem['switch'][$selected]['fields'], $prefix);
-                }
-            } elseif (isset($configitem['_type'])) {
-                $required = (isset($configitem['required'])) ? $configitem['required'] : true;
-                $type = $configitem['_type'];
-
-                // FIXME: multienum fields can well be required, meaning that
-                // you need to select at least one entry. Changing this before
-                // Horde 4.0 would break a lot of configuration files though.
-                if ($type == 'multienum' || $type == 'header' ||
-                    $type == 'description') {
-                    $required = false;
-                }
-
-                $var_params = ($type == 'multienum' || $type == 'enum')
-                    ? array($configitem['values'])
-                    : array();
-
-                if ($type == 'header' || $type == 'description') {
-                    $name = $configitem['desc'];
-                    $desc = null;
-                } else {
-                    $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
-                    $desc = $configitem['desc'];
-                    if ($type == 'php') {
-                        $type = 'text';
-                        $desc .= "\nEnter a valid PHP expression.";
-                    }
-                }
-
-                $v = &$this->addVariable($name, $varname, $type, $required, false, $desc, $var_params);
-                if (isset($configitem['default'])) {
-                    $v->setDefault($configitem['default']);
-                }
-                if (!empty($configitem['is_default'])) {
-                    $v->_new = true;
-                }
-            } else {
-                $this->_buildVariables($configitem, $prefixedname);
-            }
-        }
-    }
-
-}
diff --git a/framework/Core/lib/Horde/Config/Form.php b/framework/Core/lib/Horde/Config/Form.php
new file mode 100644 (file)
index 0000000..b319428
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+/**
+ * A Horde_Form:: form that implements a user interface for the config
+ * system.
+ *
+ * Copyright 2002-2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @author  Chuck Hagenbuch <chuck@horde.org>
+ * @package Core
+ */
+class Horde_Config_Form extends Horde_Form
+{
+    /**
+     * Don't use form tokens for the configuration form - while
+     * generating configuration info, things like the Token system
+     * might not work correctly. This saves some headaches.
+     *
+     * @var boolean
+     */
+    protected $_useFormToken = false;
+
+    /**
+     * Contains the Horde_Config object that this form represents.
+     *
+     * @var Horde_Config
+     */
+    protected $_xmlConfig;
+
+    /**
+     * Contains the Horde_Variables object of this form.
+     *
+     * @var Horde_Variables
+     */
+    protected $_vars;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Variables &$vars  The variables object of this form.
+     * @param string $app             The name of the application that this
+     *                                configuration form is for.
+     */
+    public function __construct(&$vars, $app)
+    {
+        parent::__construct($vars);
+
+        $this->_xmlConfig = new Horde_Config($app);
+        $this->_vars = &$vars;
+        $config = $this->_xmlConfig->readXMLConfig();
+        $this->addHidden('', 'app', 'text', true);
+        $this->_buildVariables($config);
+    }
+
+    /**
+     * Builds the form based on the specified level of the configuration tree.
+     *
+     * @param array $config   The portion of the configuration tree for that
+     *                        the form fields should be created.
+     * @param string $prefix  A string representing the current position
+     *                        inside the configuration tree.
+     */
+    protected function _buildVariables($config, $prefix = '')
+    {
+        if (!is_array($config)) {
+            return;
+        }
+
+        foreach ($config as $name => $configitem) {
+            $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name;
+            $varname = str_replace('|', '__', $prefixedname);
+            if ($configitem == 'placeholder') {
+                continue;
+            } elseif (isset($configitem['tab'])) {
+                $this->setSection($configitem['tab'], $configitem['desc']);
+            } elseif (isset($configitem['switch'])) {
+                $selected = $this->_vars->getExists($varname, $wasset);
+                $var_params = array();
+                $select_option = true;
+                if (is_bool($configitem['default'])) {
+                    $configitem['default'] = $configitem['default'] ? 'true' : 'false';
+                }
+                foreach ($configitem['switch'] as $option => $case) {
+                    $var_params[$option] = $case['desc'];
+                    if ($option == $configitem['default']) {
+                        $select_option = false;
+                        if (!$wasset) {
+                            $selected = $option;
+                        }
+                    }
+                }
+
+                $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
+                $desc = $configitem['desc'];
+
+                $v = &$this->addVariable($name, $varname, 'enum', true, false, $desc, array($var_params, $select_option));
+                if (array_key_exists('default', $configitem)) {
+                    $v->setDefault($configitem['default']);
+                }
+                if (!empty($configitem['is_default'])) {
+                    $v->_new = true;
+                }
+                $v_action = Horde_Form_Action::factory('reload');
+                $v->setAction($v_action);
+                if (isset($selected) && isset($configitem['switch'][$selected])) {
+                    $this->_buildVariables($configitem['switch'][$selected]['fields'], $prefix);
+                }
+            } elseif (isset($configitem['_type'])) {
+                $required = (isset($configitem['required'])) ? $configitem['required'] : true;
+                $type = $configitem['_type'];
+
+                // FIXME: multienum fields can well be required, meaning that
+                // you need to select at least one entry. Changing this before
+                // Horde 4.0 would break a lot of configuration files though.
+                if ($type == 'multienum' || $type == 'header' ||
+                    $type == 'description') {
+                    $required = false;
+                }
+
+                $var_params = ($type == 'multienum' || $type == 'enum')
+                    ? array($configitem['values'])
+                    : array();
+
+                if ($type == 'header' || $type == 'description') {
+                    $name = $configitem['desc'];
+                    $desc = null;
+                } else {
+                    $name = '$conf[' . implode('][', explode('|', $prefixedname)) . ']';
+                    $desc = $configitem['desc'];
+                    if ($type == 'php') {
+                        $type = 'text';
+                        $desc .= "\nEnter a valid PHP expression.";
+                    }
+                }
+
+                $v = &$this->addVariable($name, $varname, $type, $required, false, $desc, $var_params);
+                if (isset($configitem['default'])) {
+                    $v->setDefault($configitem['default']);
+                }
+                if (!empty($configitem['is_default'])) {
+                    $v->_new = true;
+                }
+            } else {
+                $this->_buildVariables($configitem, $prefixedname);
+            }
+        }
+    }
+
+}
index d3b7c7f..6b2d8f7 100644 (file)
@@ -49,12 +49,15 @@ Application Framework.
    <dir name="lib">
     <dir name="Horde">
      <file name="Config.php" role="php" />
+     <dir name="Config">
+      <file name="Form.php" role="php" />
+     </dir> <!-- /lib/Horde/Config -->
      <dir name="Core">
       <dir name="Autoloader">
        <dir name="Callback">
         <dir name="Mime.php" role="php" />
-       </dir>
-      </dir>
+       </dir> <!-- /lib/Horde/Core/Autoloader/Callback -->
+      </dir> <!-- /lib/Horde/Core/Autoloader -->
       <dir name="Binder">
        <file name="Cache.php" role="php" />
        <file name="Db.php" role="php" />
@@ -145,6 +148,7 @@ Application Framework.
  <phprelease>
   <filelist>
    <install name="lib/Horde/Config.php" as="Horde/Config.php" />
+   <install name="lib/Horde/Config/Form.php" as="Horde/Config/Form.php" />
    <install name="lib/Horde/Core/Autoloader/Callback/Mime.php" as="Horde/Core/Autoloader/Callback/Mime.php" />
    <install name="lib/Horde/Core/Binder/Cache.php" as="Horde/Core/Binder/Cache.php" />
    <install name="lib/Horde/Core/Binder/Db.php" as="Horde/Core/Binder/Db.php" />
index f344f81..44b17cb 100644 (file)
@@ -29,8 +29,7 @@ if (empty($app) || !in_array($app, $registry->listAllApps())) {
 
 $vars = Horde_Variables::getDefaultVariables();
 
-require_once 'Horde/Config.php';
-$form = new ConfigForm($vars, $app);
+$form = new Horde_Config_Form($vars, $app);
 $form->setButtons(sprintf(_("Generate %s Configuration"), $appname));
 if (file_exists($registry->get('fileroot', $app) . '/config/conf.bak.php')) {
     $form->appendButtons(_("Revert Configuration"));