当前位置: 首页>>代码示例>>PHP>>正文


PHP Horde_Variables::getExists方法代码示例

本文整理汇总了PHP中Horde_Variables::getExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Variables::getExists方法的具体用法?PHP Horde_Variables::getExists怎么用?PHP Horde_Variables::getExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Horde_Variables的用法示例。


在下文中一共展示了Horde_Variables::getExists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _generatePHPConfig

 /**
  * Generates the configuration file items for a part of the configuration
  * tree.
  *
  * @param array $section             An associative array containing the
  *                                   part of the traversed XML
  *                                   configuration tree that should be
  *                                   processed.
  * @param string $prefix             A configuration prefix determining
  *                                   the current position inside the
  *                                   configuration file. This prefix will
  *                                   be translated to keys of the $conf
  *                                   array in the generated configuration
  *                                   file.
  * @param Horde_Variables $formvars  The processed configuration form
  *                                   data.
  */
 protected function _generatePHPConfig($section, $prefix, $formvars)
 {
     if (!is_array($section)) {
         return;
     }
     foreach ($section as $name => $configitem) {
         if (is_array($configitem) && isset($configitem['tab'])) {
             continue;
         }
         $prefixedname = empty($prefix) ? $name : $prefix . '|' . $name;
         $configname = str_replace('|', '__', $prefixedname);
         $quote = !isset($configitem['quote']) || $configitem['quote'] !== false;
         if ($configitem == 'placeholder') {
             $this->_phpConfig .= '$conf[\'' . str_replace('|', '\'][\'', $prefix) . "'] = array();\n";
         } elseif (isset($configitem['switch'])) {
             $val = $formvars->getExists($configname, $wasset);
             if (!$wasset) {
                 $val = isset($configitem['default']) ? $configitem['default'] : null;
             }
             if (isset($configitem['switch'][$val])) {
                 $value = $val;
                 if ($quote && $value != 'true' && $value != 'false') {
                     $value = "'" . $value . "'";
                 }
                 $this->_generatePHPConfig($configitem['switch'][$val]['fields'], $prefix, $formvars);
             }
         } elseif (isset($configitem['_type'])) {
             $val = $formvars->getExists($configname, $wasset);
             if (!$wasset && (array_key_exists('is_default', $configitem) && $configitem['is_default'] || !array_key_exists('is_default', $configitem))) {
                 $val = isset($configitem['default']) ? $configitem['default'] : null;
             }
             $type = $configitem['_type'];
             switch ($type) {
                 case 'multienum':
                     if (is_array($val)) {
                         $encvals = array();
                         foreach ($val as $v) {
                             $encvals[] = $this->_quote($v);
                         }
                         $arrayval = "'" . implode('\', \'', $encvals) . "'";
                         if ($arrayval == "''") {
                             $arrayval = '';
                         }
                     } else {
                         $arrayval = '';
                     }
                     $value = 'array(' . $arrayval . ')';
                     break;
                 case 'boolean':
                     if (is_bool($val)) {
                         $value = $val ? 'true' : 'false';
                     } else {
                         $value = $val == 'on' ? 'true' : 'false';
                     }
                     break;
                 case 'stringlist':
                     $values = explode(',', $val);
                     if (!is_array($values)) {
                         $value = "array('" . $this->_quote(trim($values)) . "')";
                     } else {
                         $encvals = array();
                         foreach ($values as $v) {
                             $encvals[] = $this->_quote(trim($v));
                         }
                         $arrayval = "'" . implode('\', \'', $encvals) . "'";
                         if ($arrayval == "''") {
                             $arrayval = '';
                         }
                         $value = 'array(' . $arrayval . ')';
                     }
                     break;
                 case 'int':
                     if (strlen($val)) {
                         $value = (int) $val;
                     }
                     break;
                 case 'octal':
                     $value = sprintf('0%o', octdec($val));
                     break;
                 case 'header':
                 case 'description':
                     break;
                 default:
//.........这里部分代码省略.........
开发者ID:jubinpatel,项目名称:horde,代码行数:101,代码来源:Config.php

示例2: _buildVariables

 /**
  * 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 ($this->_fillvars) {
                     $this->_vars->set($varname, $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'];
             if ($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 ($this->_fillvars) {
                     switch ($type) {
                         case 'boolean':
                             if ($configitem['default']) {
                                 $this->_vars->set($varname, 'on');
                             }
                             break;
                         case 'int':
                             $this->_vars->set($varname, (string) $configitem['default']);
                             break;
                         default:
                             $this->_vars->set($varname, $configitem['default']);
                             break;
                     }
                 }
             }
             if (!empty($configitem['is_default'])) {
                 $v->_new = true;
             }
         } else {
             $this->_buildVariables($configitem, $prefixedname);
         }
     }
 }
开发者ID:jubinpatel,项目名称:horde,代码行数:98,代码来源:Form.php


注:本文中的Horde_Variables::getExists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。