예제 #1
0
function is_yaml_array_of_integers($yaml_str)
{
    if (!is_string($yaml_str)) {
        return false;
    }
    $val = @yaml_decode($yaml_str);
    return is_array_of_integers($val);
}
예제 #2
0
파일: opts.php 프로젝트: simpl/datapipe
function check_opt_type($cmd, $opt, $name, $types, $msg_type = 'error')
{
    # check if the opt is of the right type
    $types = explode(',', $types);
    foreach ($types as $i => $type) {
        # check for special enum types
        $sub_types = explode(':', $type);
        switch ($sub_types[0]) {
            case 'data_join_type':
                $main_type = 'enum';
                $test = 'inner|outer';
                break;
            case 'data_source_type':
                $main_type = 'enum';
                $test = 'file|pass|search';
                break;
            case 'data_structure_type':
                $main_type = 'enum';
                $test = 'list_of_objects|list_of_columns';
                break;
            case 'data_type':
                $main_type = 'enum';
                $test = 'index|array_of_indexes';
                break;
            case 'document_file_type':
                $main_type = 'enum';
                $test = 'json|yaml';
                break;
            case 'filter_data_type':
                $main_type = 'enum';
                $test = 'join';
                break;
            case 'http_request_method':
                $main_type = 'enum';
                $test = 'get|post';
                break;
            case 'message_type':
                $main_type = 'enum';
                $test = 'error|warning|notice|none';
                break;
            case 'suredone_action':
                $main_type = 'enum';
                $test = 'add|edit';
                break;
            case 'suredone_type':
                $main_type = 'enum';
                $test = 'categories|items|orders|pages|posts|tags';
                break;
            default:
                $main_type = $sub_types[0];
                $test = @$sub_types[1];
                break;
        }
        # reset the types
        $type = "{$main_type}";
        if ($test) {
            $type .= ":{$test}";
        }
        $types[$i] = $type;
        # check the main types
        # TODO: add integer:min=x,max=y
        switch ($main_type) {
            case 'array':
                $true = is_array($opt);
                break;
            case 'array_of_arrays':
                $true = is_array_of_arrays($opt);
                break;
            case 'array_of_integers':
                $true = is_array_of_integers($opt);
                break;
            case 'array_of_strings':
                $true = is_array_of_strings($opt);
                break;
            case 'boolean':
                $true = is_bool($opt);
                break;
            case 'enum':
                $true = is_enum($opt, $test);
                break;
                /*case  'dir'                     :   $true = is_local_dir                ($opt);         break;
                  case  'file'                    :   $true = is_local_file               ($opt);         break;*/
            /*case  'dir'                     :   $true = is_local_dir                ($opt);         break;
              case  'file'                    :   $true = is_local_file               ($opt);         break;*/
            case 'float':
                $true = is_float($opt);
                break;
            case 'integer':
                $true = is_int($opt);
                break;
            case 'positive_integer':
                $true = is_positive_int($opt);
                break;
            case 'string':
                $true = is_string($opt);
                break;
            case 'yaml_array':
                $true = is_yaml_array($opt);
                break;
            case 'yaml_array_of_integers':
                $true = is_yaml_array_of_integers($opt);
                break;
            case 'yaml_array_of_strings':
                $true = is_yaml_array_of_strings($opt);
                break;
            default:
                return error($cmd, "invalid check opt type '{$type}'");
        }
        if ($true) {
            return true;
        }
    }
    # build the types string
    $types_str = $types[0];
    if (count($types) > 0) {
        for ($i = 1; $i < count($types); $i++) {
            $type = $types[$i];
            $types_str = "{$types_str} or {$type}";
        }
    }
    # build the message string
    $name = full_opt_name($cmd, $name);
    $msg = "option '{$name}' is not of type {$types_str}";
    message($cmd, $msg, $msg_type);
    return false;
}