Exemple #1
0
 /**
  * Returns validator list
  *
  * @param ConfigFile $cf Config file instance
  *
  * @return array
  */
 public static function getValidators(ConfigFile $cf)
 {
     static $validators = null;
     if ($validators === null) {
         $validators = $cf->getDbEntry('_validators', array());
         if (!defined('PMA_SETUP')) {
             // not in setup script: load additional validators for user
             // preferences we need original config values not overwritten
             // by user preferences, creating a new PMA_Config instance is a
             // better idea than hacking into its code
             $uvs = $cf->getDbEntry('_userValidators', array());
             foreach ($uvs as $field => $uv_list) {
                 $uv_list = (array) $uv_list;
                 foreach ($uv_list as &$uv) {
                     if (!is_array($uv)) {
                         continue;
                     }
                     for ($i = 1; $i < count($uv); $i++) {
                         if (substr($uv[$i], 0, 6) == 'value:') {
                             $uv[$i] = PMA_arrayRead(substr($uv[$i], 6), $GLOBALS['PMA_Config']->base_settings);
                         }
                     }
                 }
                 $validators[$field] = isset($validators[$field]) ? array_merge((array) $validators[$field], $uv_list) : $uv_list;
             }
         }
     }
     return $validators;
 }
 /**
  * Returns allowed values for select fields
  *
  * @param string $option_path Option path
  *
  * @return array
  */
 public function getOptionValueList($option_path)
 {
     $value = $this->_configFile->getDbEntry($option_path);
     if ($value === null) {
         trigger_error("{$option_path} - select options not defined", E_USER_ERROR);
         return array();
     }
     if (!is_array($value)) {
         trigger_error("{$option_path} - not a static value list", E_USER_ERROR);
         return array();
     }
     // convert array('#', 'a', 'b') to array('a', 'b')
     if (isset($value[0]) && $value[0] === '#') {
         // remove first element ('#')
         array_shift($value);
         // $value has keys and value names, return it
         return $value;
     }
     // convert value list array('a', 'b') to array('a' => 'a', 'b' => 'b')
     $has_string_keys = false;
     $keys = array();
     for ($i = 0, $nb = count($value); $i < $nb; $i++) {
         if (!isset($value[$i])) {
             $has_string_keys = true;
             break;
         }
         $keys[] = is_bool($value[$i]) ? (int) $value[$i] : $value[$i];
     }
     if (!$has_string_keys) {
         $value = array_combine($keys, $value);
     }
     // $value has keys and value names, return it
     return $value;
 }
Exemple #3
0
 /**
  * Test for ConfigFile::getDbEntry
  *
  * @return void
  * @test
  */
 public function testGetDbEntry()
 {
     $cfg_db = array();
     include './libraries/config.values.php';
     // verify that $cfg_db read from config.values.php is valid
     $this->assertGreaterThanOrEqual(20, count($cfg_db));
     $this->assertEquals($cfg_db['Servers'][1]['port'], $this->object->getDbEntry('Servers/1/port'));
     $this->assertNull($this->object->getDbEntry('no such key'));
     $this->assertEquals(array(1), $this->object->getDbEntry('no such key', array(1)));
 }