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


PHP rest_parse_date函数代码示例

本文整理汇总了PHP中rest_parse_date函数的典型用法代码示例。如果您正苦于以下问题:PHP rest_parse_date函数的具体用法?PHP rest_parse_date怎么用?PHP rest_parse_date使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: prepare_field_value_from_json

 /**
  * Prepares incoming data from the json or $_REQUEST parameters for the models'
  * "$query_params". 
  * @param EE_Model_Field_Base $field_obj
  * @param mixed $original_value
  * @param string $requested_version
  * @return mixed
  */
 public static function prepare_field_value_from_json($field_obj, $original_value, $requested_version)
 {
     $new_value = null;
     if ($field_obj instanceof \EE_Infinite_Integer_Field && in_array($original_value, array(null, ''), true)) {
         $new_value = EE_INF;
     } elseif ($field_obj instanceof \EE_Datetime_Field) {
         $new_value = rest_parse_date($original_value);
     } else {
         $new_value = $original_value;
     }
     return $new_value;
 }
开发者ID:aaronfrey,项目名称:PepperLillie-GSP,代码行数:20,代码来源:Model_Data_Translator.php

示例2: rest_validate_request_arg

 /**
  * Validate a request argument based on details registered to the route.
  *
  * @param  mixed            $value
  * @param  WP_REST_Request  $request
  * @param  string           $param
  * @return WP_Error|boolean
  */
 function rest_validate_request_arg($value, $request, $param)
 {
     $attributes = $request->get_attributes();
     if (!isset($attributes['args'][$param]) || !is_array($attributes['args'][$param])) {
         return true;
     }
     $args = $attributes['args'][$param];
     if (!empty($args['enum'])) {
         if (!in_array($value, $args['enum'])) {
             /* translators: 1: parameter 2: arguments */
             return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not one of %2$s', 'woocommerce'), $param, implode(', ', $args['enum'])));
         }
     }
     if ('integer' === $args['type'] && !is_numeric($value)) {
         /* translators: 1: parameter 2: integer type */
         return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s', 'woocommerce'), $param, 'integer'));
     }
     if ('boolean' === $args['type'] && !rest_is_boolean($value)) {
         /* translators: 1: parameter 2: boolean type */
         return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s', 'woocommerce'), $value, 'boolean'));
     }
     if ('string' === $args['type'] && !is_string($value)) {
         /* translators: 1: parameter 2: string type */
         return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s', 'woocommerce'), $param, 'string'));
     }
     if (isset($args['format'])) {
         switch ($args['format']) {
             case 'date-time':
                 if (!rest_parse_date($value)) {
                     return new WP_Error('rest_invalid_date', __('The date you provided is invalid.', 'woocommerce'));
                 }
                 break;
             case 'email':
                 if (!is_email($value)) {
                     return new WP_Error('rest_invalid_email', __('The email address you provided is invalid.', 'woocommerce'));
                 }
                 break;
             case 'ipv4':
                 if (!rest_is_ip_address($value)) {
                     /* translators: %s: IP address */
                     return new WP_Error('rest_invalid_param', sprintf(__('%s is not a valid IP address.', 'woocommerce'), $value));
                 }
                 break;
         }
     }
     if (in_array($args['type'], array('numeric', 'integer')) && (isset($args['minimum']) || isset($args['maximum']))) {
         if (isset($args['minimum']) && !isset($args['maximum'])) {
             if (!empty($args['exclusiveMinimum']) && $value <= $args['minimum']) {
                 return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be greater than %2$d (exclusive)', 'woocommerce'), $param, $args['minimum']));
             } elseif (empty($args['exclusiveMinimum']) && $value < $args['minimum']) {
                 return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be greater than %2$d (inclusive)', 'woocommerce'), $param, $args['minimum']));
             }
         } elseif (isset($args['maximum']) && !isset($args['minimum'])) {
             if (!empty($args['exclusiveMaximum']) && $value >= $args['maximum']) {
                 return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be less than %2$d (exclusive)', 'woocommerce'), $param, $args['maximum']));
             } elseif (empty($args['exclusiveMaximum']) && $value > $args['maximum']) {
                 return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be less than %2$d (inclusive)', 'woocommerce'), $param, $args['maximum']));
             }
         } elseif (isset($args['maximum']) && isset($args['minimum'])) {
             if (!empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                 if ($value >= $args['maximum'] || $value <= $args['minimum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (exclusive) and %3$d (exclusive)', 'woocommerce'), $param, $args['minimum'], $args['maximum']));
                 }
             } elseif (empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                 if ($value >= $args['maximum'] || $value < $args['minimum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (inclusive) and %3$d (exclusive)', 'woocommerce'), $param, $args['minimum'], $args['maximum']));
                 }
             } elseif (!empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                 if ($value > $args['maximum'] || $value <= $args['minimum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (exclusive) and %3$d (inclusive)', 'woocommerce'), $param, $args['minimum'], $args['maximum']));
                 }
             } elseif (empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                 if ($value > $args['maximum'] || $value < $args['minimum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (inclusive) and %3$d (inclusive)', 'woocommerce'), $param, $args['minimum'], $args['maximum']));
                 }
             }
         }
     }
     return true;
 }
开发者ID:woocommerce,项目名称:woocommerce,代码行数:88,代码来源:wp-rest-functions.php

示例3: validate_schema_property

 /**
  * Validate an parameter value that's based on a property from the item schema.
  *
  * @param  mixed $value
  * @param  WP_REST_Request $request
  * @param  string $parameter
  * @return WP_Error|bool
  */
 public function validate_schema_property($value, $request, $parameter)
 {
     /**
      * We don't currently validate against empty values, as lots of checks
      * can unintentionally fail, as the callback will often handle an empty
      * value it's self.
      */
     if (!$value) {
         return true;
     }
     $schema = $this->get_item_schema();
     if (!isset($schema['properties'][$parameter])) {
         return true;
     }
     $property = $schema['properties'][$parameter];
     if (!empty($property['enum'])) {
         if (!in_array($value, $property['enum'])) {
             return new WP_Error('rest_invalid_param', sprintf(__('%s is not one of %s'), $parameter, implode(', ', $property['enum'])));
         }
     }
     if ('integer' === $property['type'] && !is_numeric($value)) {
         return new WP_Error('rest_invalid_param', sprintf(__('%s is not of type %s'), $parameter, 'integer'));
     }
     if ('string' === $property['type'] && !is_string($value)) {
         return new WP_Error('rest_invalid_param', sprintf(__('%s is not of type %s'), $parameter, 'string'));
     }
     if (isset($property['format'])) {
         switch ($property['format']) {
             case 'date-time':
                 if (!rest_parse_date($value)) {
                     return new WP_Error('rest_invalid_date', __('The date you provided is invalid.'));
                 }
                 break;
             case 'email':
                 if (!is_email($value)) {
                     return new WP_Error('rest_invalid_email', __('The email address you provided is invalid.'));
                 }
                 break;
         }
     }
     return true;
 }
开发者ID:alexandrinos,项目名称:wp-api-rest,代码行数:50,代码来源:class-wp-rest-controller.php

示例4: rest_validate_value_from_schema

/**
 * Validate a value based on a schema.
 *
 * @param mixed  $value The value to validate.
 * @param array  $args  Schema array to use for validation.
 * @param string $param The parameter name, used in error messages.
 * @return true|WP_Error
 */
function rest_validate_value_from_schema($value, $args, $param = '')
{
    if ('array' === $args['type']) {
        if (!is_array($value)) {
            $value = preg_split('/[\\s,]+/', $value);
        }
        foreach ($value as $index => $v) {
            $is_valid = rest_validate_value_from_schema($v, $args['items'], $param . '[' . $index . ']');
            if (is_wp_error($is_valid)) {
                return $is_valid;
            }
        }
    }
    if (!empty($args['enum'])) {
        if (!in_array($value, $args['enum'], true)) {
            return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not one of %2$s.'), $param, implode(', ', $args['enum'])));
        }
    }
    if (in_array($args['type'], array('integer', 'number')) && !is_numeric($value)) {
        return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s.'), $param, $args['type']));
    }
    if ('integer' === $args['type'] && round(floatval($value)) !== floatval($value)) {
        return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s.'), $param, 'integer'));
    }
    if ('boolean' === $args['type'] && !rest_is_boolean($value)) {
        return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s.'), $value, 'boolean'));
    }
    if ('string' === $args['type'] && !is_string($value)) {
        return new WP_Error('rest_invalid_param', sprintf(__('%1$s is not of type %2$s.'), $param, 'string'));
    }
    if (isset($args['format'])) {
        switch ($args['format']) {
            case 'date-time':
                if (!rest_parse_date($value)) {
                    return new WP_Error('rest_invalid_date', __('The date you provided is invalid.'));
                }
                break;
            case 'email':
                // is_email() checks for 3 characters (a@b), but
                // wp_handle_comment_submission() requires 6 characters (a@b.co)
                //
                // https://core.trac.wordpress.org/ticket/38506
                if (!is_email($value) || strlen($value) < 6) {
                    return new WP_Error('rest_invalid_email', __('The email address you provided is invalid.'));
                }
                break;
            case 'ipv4':
                if (!rest_is_ip_address($value)) {
                    return new WP_Error('rest_invalid_param', sprintf(__('%s is not a valid IP address.'), $value));
                }
                break;
        }
    }
    if (in_array($args['type'], array('number', 'integer'), true) && (isset($args['minimum']) || isset($args['maximum']))) {
        if (isset($args['minimum']) && !isset($args['maximum'])) {
            if (!empty($args['exclusiveMinimum']) && $value <= $args['minimum']) {
                return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be greater than %2$d (exclusive)'), $param, $args['minimum']));
            } elseif (empty($args['exclusiveMinimum']) && $value < $args['minimum']) {
                return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be greater than %2$d (inclusive)'), $param, $args['minimum']));
            }
        } elseif (isset($args['maximum']) && !isset($args['minimum'])) {
            if (!empty($args['exclusiveMaximum']) && $value >= $args['maximum']) {
                return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be less than %2$d (exclusive)'), $param, $args['maximum']));
            } elseif (empty($args['exclusiveMaximum']) && $value > $args['maximum']) {
                return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be less than %2$d (inclusive)'), $param, $args['maximum']));
            }
        } elseif (isset($args['maximum']) && isset($args['minimum'])) {
            if (!empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                if ($value >= $args['maximum'] || $value <= $args['minimum']) {
                    return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (exclusive) and %3$d (exclusive)'), $param, $args['minimum'], $args['maximum']));
                }
            } elseif (empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                if ($value >= $args['maximum'] || $value < $args['minimum']) {
                    return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (inclusive) and %3$d (exclusive)'), $param, $args['minimum'], $args['maximum']));
                }
            } elseif (!empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                if ($value > $args['maximum'] || $value <= $args['minimum']) {
                    return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (exclusive) and %3$d (inclusive)'), $param, $args['minimum'], $args['maximum']));
                }
            } elseif (empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                if ($value > $args['maximum'] || $value < $args['minimum']) {
                    return new WP_Error('rest_invalid_param', sprintf(__('%1$s must be between %2$d (inclusive) and %3$d (inclusive)'), $param, $args['minimum'], $args['maximum']));
                }
            }
        }
    }
    return true;
}
开发者ID:023yangbo,项目名称:WordPress,代码行数:96,代码来源:rest-api.php

示例5: rest_get_date_with_gmt

/**
 * Retrieves a local date with its GMT equivalent, in MySQL datetime format.
 *
 * @since 4.4.0
 *
 * @see rest_parse_date()
 *
 * @param string $date      RFC3339 timestamp.
 * @param bool   $force_utc Whether a UTC timestamp should be forced. Default false.
 * @return array|null Local and UTC datetime strings, in MySQL datetime format (Y-m-d H:i:s),
 *                    null on failure.
 */
function rest_get_date_with_gmt($date, $force_utc = false)
{
    $date = rest_parse_date($date, $force_utc);
    if (empty($date)) {
        return null;
    }
    $utc = date('Y-m-d H:i:s', $date);
    $local = get_date_from_gmt($utc);
    return array($local, $utc);
}
开发者ID:hadywisam,项目名称:WordPress,代码行数:22,代码来源:rest-functions.php

示例6: rest_validate_request_arg

 /**
  * Validate a request argument based on details registered to the route.
  *
  * @param  mixed            $value
  * @param  WP_REST_Request  $request
  * @param  string           $param
  * @return WP_Error|boolean
  */
 function rest_validate_request_arg($value, $request, $param)
 {
     $attributes = $request->get_attributes();
     if (!isset($attributes['args'][$param]) || !is_array($attributes['args'][$param])) {
         return true;
     }
     $args = $attributes['args'][$param];
     if (!empty($args['enum'])) {
         if (!in_array($value, $args['enum'])) {
             return new WP_Error('rest_invalid_param', sprintf(__('%s is not one of %s'), $param, implode(', ', $args['enum'])));
         }
     }
     if ('integer' === $args['type'] && !is_numeric($value)) {
         return new WP_Error('rest_invalid_param', sprintf(__('%s is not of type %s'), $param, 'integer'));
     }
     if ('string' === $args['type'] && !is_string($value)) {
         return new WP_Error('rest_invalid_param', sprintf(__('%s is not of type %s'), $param, 'string'));
     }
     if (isset($args['format'])) {
         switch ($args['format']) {
             case 'date-time':
                 if (!rest_parse_date($value)) {
                     return new WP_Error('rest_invalid_date', __('The date you provided is invalid.'));
                 }
                 break;
             case 'email':
                 if (!is_email($value)) {
                     return new WP_Error('rest_invalid_email', __('The email address you provided is invalid.'));
                 }
                 break;
         }
     }
     if (in_array($args['type'], array('numeric', 'integer')) && (isset($args['minimum']) || isset($args['maximum']))) {
         if (isset($args['minimum']) && !isset($args['maximum'])) {
             if (!empty($args['exclusiveMinimum']) && $value <= $args['minimum']) {
                 return new WP_Error('rest_invalid_param', sprintf(__('%s must be greater than %d (exclusive)'), $param, $args['minimum']));
             } else {
                 if (empty($args['exclusiveMinimum']) && $value < $args['minimum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%s must be greater than %d (inclusive)'), $param, $args['minimum']));
                 }
             }
         } else {
             if (isset($args['maximum']) && !isset($args['minimum'])) {
                 if (!empty($args['exclusiveMaximum']) && $value >= $args['maximum']) {
                     return new WP_Error('rest_invalid_param', sprintf(__('%s must be less than %d (exclusive)'), $param, $args['maximum']));
                 } else {
                     if (empty($args['exclusiveMaximum']) && $value > $args['maximum']) {
                         return new WP_Error('rest_invalid_param', sprintf(__('%s must be less than %d (inclusive)'), $param, $args['maximum']));
                     }
                 }
             } else {
                 if (isset($args['maximum']) && isset($args['minimum'])) {
                     if (!empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                         if ($value >= $args['maximum'] || $value <= $args['minimum']) {
                             return new WP_Error('rest_invalid_param', sprintf(__('%s must be between %d (exclusive) and %d (exclusive)'), $param, $args['minimum'], $args['maximum']));
                         }
                     } else {
                         if (empty($args['exclusiveMinimum']) && !empty($args['exclusiveMaximum'])) {
                             if ($value >= $args['maximum'] || $value < $args['minimum']) {
                                 return new WP_Error('rest_invalid_param', sprintf(__('%s must be between %d (inclusive) and %d (exclusive)'), $param, $args['minimum'], $args['maximum']));
                             }
                         } else {
                             if (!empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                                 if ($value > $args['maximum'] || $value <= $args['minimum']) {
                                     return new WP_Error('rest_invalid_param', sprintf(__('%s must be between %d (exclusive) and %d (inclusive)'), $param, $args['minimum'], $args['maximum']));
                                 }
                             } else {
                                 if (empty($args['exclusiveMinimum']) && empty($args['exclusiveMaximum'])) {
                                     if ($value > $args['maximum'] || $value < $args['minimum']) {
                                         return new WP_Error('rest_invalid_param', sprintf(__('%s must be between %d (inclusive) and %d (inclusive)'), $param, $args['minimum'], $args['maximum']));
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
开发者ID:zz-james,项目名称:edibleurban2,代码行数:89,代码来源:plugin.php


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