예제 #1
0
            //if ( 'negative' == $rule['kind'] )
            /* translators: 1: type of a validation field, 2: name of a validation field, 3: validation rule */
            return sprintf(__('The %1$s %2$s is invalid and should not be %3$s!', 'glotpress'), $type_field, '<strong>' . $name_field . '</strong>', $name_rule);
        }
    }
}
class GP_Validators
{
    static $callbacks = array();
    public static function register($key, $callback, $negative_callback = null)
    {
        // TODO: add data for easier generation of error messages
        self::$callbacks[$key] = array('positive' => $callback, 'negative' => $negative_callback);
    }
    public static function unregister($key)
    {
        unset(self::$callbacks[$key]);
    }
    public static function get($key)
    {
        return gp_array_get(self::$callbacks, $key, null);
    }
}
GP_Validators::register('empty', 'gp_is_empty');
GP_Validators::register('empty_string', 'gp_is_empty_string');
GP_Validators::register('positive_int', 'gp_is_positive_int');
GP_Validators::register('int', 'gp_is_int');
GP_Validators::register('null', 'gp_is_null');
GP_Validators::register('between', 'gp_is_between');
GP_Validators::register('between_exclusive', 'gp_is_between_exclusive');
예제 #2
0
            }
        }
        return $verdict;
    }
    function construct_error_message($rule, $value)
    {
        // TODO: better error messages, should include info from callback
        return sprintf(__('The field <strong>%s</strong> has invalid value!'), $rule['field'], $value);
    }
}
class GP_Validators
{
    static $callbacks = array();
    static function register($key, $callback, $negative_callback = null)
    {
        // TODO: add data for easier generation of error messages
        self::$callbacks[$key] = array('positive' => $callback, 'negative' => $negative_callback);
    }
    static function unregister($key)
    {
        unset(self::$callbacks[$key]);
    }
    static function get($key)
    {
        return gp_array_get(self::$callbacks, $key, null);
    }
}
GP_Validators::register('empty', lambda('$value', 'empty($value)'));
GP_Validators::register('positive_int', lambda('$value', '((int)$value > 0)'));
GP_Validators::register('null', lambda('$value', 'is_null($value)'));