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


PHP ConfigFile::getServerCount方法代码示例

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


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

示例1: testGetServerCount

    /**
     * Test for ConfigFile::getServerCount
     *
     * @return void
     * @test
     */
    public function testGetServerCount()
    {
        $this->object->set('Servers/1/x', 1);
        $this->object->set('Servers/2/x', 2);
        $this->object->set('Servers/3/x', 3);
        $this->object->set('Servers/4/x', 4);
        $this->object->set('ServerDefault', 3);

        $this->assertEquals(
            4,
            $this->object->getServerCount()
        );

        $this->object->removeServer(2);
        $this->object->removeServer(2);

        $this->assertEquals(
            2,
            $this->object->getServerCount()
        );

        $this->assertLessThanOrEqual(
            2,
            $this->object->get('ServerDefault')
        );
        $this->assertEquals(
            array('Servers' => array(1 => array('x' => 1), 2 => array('x' => 4))),
            $this->object->getConfig()
        );
        $this->assertEquals(
            array('Servers/1/x' => 1, 'Servers/2/x' => 4),
            $this->object->getConfigArray()
        );
    }
开发者ID:roccivic,项目名称:phpmyadmin,代码行数:40,代码来源:PMA_ConfigFile_test.php

示例2: getConfigFile

 /**
  * Creates config file
  *
  * @param ConfigFile $cf Config file instance
  *
  * @return string
  */
 public static function getConfigFile(ConfigFile $cf)
 {
     $crlf = isset($_SESSION['eol']) && $_SESSION['eol'] == 'win' ? "\r\n" : "\n";
     $c = $cf->getConfig();
     // header
     $ret = '<?php' . $crlf . '/*' . $crlf . ' * Generated configuration file' . $crlf . ' * Generated by: phpMyAdmin ' . $GLOBALS['PMA_Config']->get('PMA_VERSION') . ' setup script' . $crlf . ' * Date: ' . date(DATE_RFC1123) . $crlf . ' */' . $crlf . $crlf;
     // servers
     if ($cf->getServerCount() > 0) {
         $ret .= "/* Servers configuration */{$crlf}\$i = 0;" . $crlf . $crlf;
         foreach ($c['Servers'] as $id => $server) {
             $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [{$id}] ", '*/', '-') . "*/" . $crlf . '$i++;' . $crlf;
             foreach ($server as $k => $v) {
                 $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
                 $ret .= "\$cfg['Servers'][\$i]['{$k}'] = " . (is_array($v) && self::_isZeroBasedArray($v) ? self::_exportZeroBasedArray($v, $crlf) : var_export($v, true)) . ';' . $crlf;
             }
             $ret .= $crlf;
         }
         $ret .= '/* End of servers configuration */' . $crlf . $crlf;
     }
     unset($c['Servers']);
     // other settings
     $persistKeys = $cf->getPersistKeysMap();
     foreach ($c as $k => $v) {
         $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
         $ret .= self::_getVarExport($k, $v, $crlf);
         if (isset($persistKeys[$k])) {
             unset($persistKeys[$k]);
         }
     }
     // keep 1d array keys which are present in $persist_keys (config.values.php)
     foreach (array_keys($persistKeys) as $k) {
         if ($GLOBALS['PMA_String']->strpos($k, '/') === false) {
             $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
             $ret .= self::_getVarExport($k, $cf->getDefault($k), $crlf);
         }
     }
     $ret .= '?' . '>';
     return $ret;
 }
开发者ID:FilipeRamosFernandes,项目名称:phpmyadmin,代码行数:46,代码来源:ConfigGenerator.class.php

示例3: getServerPart

 /**
  * Generate server part of config file
  *
  * @param ConfigFile $cf      Config file
  * @param string     $crlf    Carriage return char
  * @param array      $servers Servers list
  *
  * @return string
  */
 protected static function getServerPart(ConfigFile $cf, $crlf, $servers)
 {
     if ($cf->getServerCount() === 0) {
         return null;
     }
     $ret = "/* Servers configuration */{$crlf}\$i = 0;" . $crlf . $crlf;
     foreach ($servers as $id => $server) {
         $ret .= '/* Server: ' . strtr($cf->getServerName($id) . " [{$id}] ", '*/', '-') . "*/" . $crlf . '$i++;' . $crlf;
         foreach ($server as $k => $v) {
             $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k);
             $ret .= "\$cfg['Servers'][\$i]['{$k}'] = " . (is_array($v) && self::_isZeroBasedArray($v) ? self::_exportZeroBasedArray($v, $crlf) : var_export($v, true)) . ';' . $crlf;
         }
         $ret .= $crlf;
     }
     $ret .= '/* End of servers configuration */' . $crlf . $crlf;
     return $ret;
 }
开发者ID:hewenhao2008,项目名称:phpmyadmin,代码行数:26,代码来源:ConfigGenerator.class.php

示例4: save

 /**
  * Validates and saves form data to session
  *
  * @param array|string $forms              array of form names
  * @param bool         $allow_partial_save allows for partial form saving on
  *                                         failed validation
  *
  * @return boolean true on success (no errors and all saved)
  */
 public function save($forms, $allow_partial_save = true)
 {
     $result = true;
     $forms = (array) $forms;
     $values = array();
     $to_save = array();
     $is_setup_script = defined('PMA_SETUP');
     if ($is_setup_script) {
         $this->_loadUserprefsInfo();
     }
     $this->_errors = array();
     foreach ($forms as $form_name) {
         /* @var $form Form */
         if (isset($this->_forms[$form_name])) {
             $form = $this->_forms[$form_name];
         } else {
             continue;
         }
         // get current server id
         $change_index = $form->index === 0 ? $this->_configFile->getServerCount() + 1 : false;
         // grab POST values
         foreach ($form->fields as $field => $system_path) {
             $work_path = array_search($system_path, $this->_systemPaths);
             $key = $this->_translatedPaths[$work_path];
             $type = $form->getOptionType($field);
             // skip groups
             if ($type == 'group') {
                 continue;
             }
             // ensure the value is set
             if (!isset($_POST[$key])) {
                 // checkboxes aren't set by browsers if they're off
                 if ($type == 'boolean') {
                     $_POST[$key] = false;
                 } else {
                     $this->_errors[$form->name][] = sprintf(__('Missing data for %s'), '<i>' . PMA_langName($system_path) . '</i>');
                     $result = false;
                     continue;
                 }
             }
             // user preferences allow/disallow
             if ($is_setup_script && isset($this->_userprefsKeys[$system_path])) {
                 if (isset($this->_userprefsDisallow[$system_path]) && isset($_POST[$key . '-userprefs-allow'])) {
                     unset($this->_userprefsDisallow[$system_path]);
                 } else {
                     if (!isset($_POST[$key . '-userprefs-allow'])) {
                         $this->_userprefsDisallow[$system_path] = true;
                     }
                 }
             }
             // cast variables to correct type
             switch ($type) {
                 case 'double':
                     settype($_POST[$key], 'float');
                     break;
                 case 'boolean':
                 case 'integer':
                     if ($_POST[$key] !== '') {
                         settype($_POST[$key], $type);
                     }
                     break;
                 case 'select':
                     $successfully_validated = $this->_validateSelect($_POST[$key], $form->getOptionValueList($system_path));
                     if (!$successfully_validated) {
                         $this->_errors[$work_path][] = __('Incorrect value!');
                         $result = false;
                         continue;
                     }
                     break;
                 case 'string':
                 case 'short_string':
                     $_POST[$key] = trim($_POST[$key]);
                     break;
                 case 'array':
                     // eliminate empty values and ensure we have an array
                     $post_values = is_array($_POST[$key]) ? $_POST[$key] : explode("\n", $_POST[$key]);
                     $_POST[$key] = array();
                     $this->_fillPostArrayParameters($post_values, $key);
                     break;
             }
             // now we have value with proper type
             $values[$system_path] = $_POST[$key];
             if ($change_index !== false) {
                 $work_path = str_replace("Servers/{$form->index}/", "Servers/{$change_index}/", $work_path);
             }
             $to_save[$work_path] = $system_path;
         }
     }
     // save forms
     if (!$allow_partial_save && !empty($this->_errors)) {
         // don't look for non-critical errors
//.........这里部分代码省略.........
开发者ID:nobodypb,项目名称:phpmyadmin,代码行数:101,代码来源:FormDisplay.class.php


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