PMA\libraries\config\Validator::getValidators PHP Method

getValidators() public static method

Returns validator list
public static getValidators ( PMA\libraries\config\ConfigFile $cf ) : array
$cf PMA\libraries\config\ConfigFile Config file instance
return array
    public static function getValidators(ConfigFile $cf)
    {
        static $validators = null;
        if ($validators !== null) {
            return $validators;
        }
        $validators = $cf->getDbEntry('_validators', array());
        if (defined('PMA_SETUP')) {
            return $validators;
        }
        // not in setup script: load additional validators for user
        // preferences we need original config values not overwritten
        // by user preferences, creating a new PMA\libraries\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, $nb = count($uv); $i < $nb; $i++) {
                    if (mb_substr($uv[$i], 0, 6) == 'value:') {
                        $uv[$i] = PMA_arrayRead(mb_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;
    }

Usage Example

Example #1
0
 /**
  * Outputs HTML for the forms under the menu tab
  *
  * @param bool  $show_restore_default whether to show "restore default"
  *                                    button besides the input field
  * @param array &$js_default          stores JavaScript code
  *                                    to be displayed
  * @param array &$js                  will be updated with javascript code
  * @param bool  $show_buttons         whether show submit and reset button
  *
  * @return string $htmlOutput
  */
 private function _displayForms($show_restore_default, array &$js_default, array &$js, $show_buttons)
 {
     $htmlOutput = '';
     $validators = Validator::getValidators($this->_configFile);
     foreach ($this->_forms as $form) {
         /* @var $form Form */
         $form_desc = isset($GLOBALS["strConfigForm_{$form->name}_desc"]) ? PMA_lang("Form_{$form->name}_desc") : '';
         $form_errors = isset($this->_errors[$form->name]) ? $this->_errors[$form->name] : null;
         $htmlOutput .= PMA_displayFieldsetTop(PMA_lang("Form_{$form->name}"), $form_desc, $form_errors, array('id' => $form->name));
         foreach ($form->fields as $field => $path) {
             $work_path = array_search($path, $this->_systemPaths);
             $translated_path = $this->_translatedPaths[$work_path];
             // always true/false for user preferences display
             // otherwise null
             $userprefs_allow = isset($this->_userprefsKeys[$path]) ? !isset($this->_userprefsDisallow[$path]) : null;
             // display input
             $htmlOutput .= $this->_displayFieldInput($form, $field, $path, $work_path, $translated_path, $show_restore_default, $userprefs_allow, $js_default);
             // register JS validators for this field
             if (isset($validators[$path])) {
                 PMA_addJsValidate($translated_path, $validators[$path], $js);
             }
         }
         $htmlOutput .= PMA_displayFieldsetBottom($show_buttons);
     }
     return $htmlOutput;
 }