rest_find_any_matching_schema()

最后更新于:2021-11-27 23:35:07

rest_find_any_matching_schema( mixed$value, array$args, string$param)

Finds the matching schema among the “anyOf” schemas.

参数

$value

(mixed) (Required) The value to validate.

$args

(array) (Required) The schema array to use.

$param

(string) (Required) The parameter name, used in error messages.

响应

(array|GC_Error) The matching schema or GC_Error instance if all schemas do not match.

源文件

文件: gc-includes/rest-api.php

function rest_find_any_matching_schema( $value, $args, $param ) {
	$errors = array();

	foreach ( $args['anyOf'] as $index => $schema ) {
		if ( ! isset( $schema['type'] ) && isset( $args['type'] ) ) {
			$schema['type'] = $args['type'];
		}

		$is_valid = rest_validate_value_from_schema( $value, $schema, $param );
		if ( ! is_gc_error( $is_valid ) ) {
			return $schema;
		}

		$errors[] = array(
			'error_object' => $is_valid,
			'schema'       => $schema,
			'index'        => $index,
		);
	}

	return rest_get_combining_operation_error( $value, $param, $errors );
}