Validation
in package
Service class validating checkout field schema.
Table of Contents
- DATA_REF_KEYWORDS = ['multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems', 'minItems', 'uniqueItems', 'maxProperties', 'minProperties', 'required', 'enum', 'format']
- Keywords that may hold a `$data` reference instead of a literal value, because the base document schema we have doesn't include those.
- FORMAT_LIMIT_KEYWORDS = ['formatMinimum', 'formatMaximum', 'formatExclusiveMinimum', 'formatExclusiveMaximum']
- Date comparison keywords shared with ajv-formats.
- $meta_schema_json : string
- Meta schema.
- get_field_schema_with_context() : array<string|int, mixed>
- Get the field schema with context.
- has_field_schema() : bool
- Check if the fields have defined schema.
- is_valid_schema() : bool|WP_Error
- Validate meta schema for field rules.
- validate_document_object() : bool|WP_Error
- Validate the field rules.
- build_meta_schema() : string
- Adds $data references and date comparisons to the draft-07 meta schema.
- format_schema_error() : string
- Describes schema errors at the failing keyword instead of the outer schema wrapper.
- schema_is_unwrapped() : bool
- Check if the schema is unwrapped (has cart, checkout, customer, as top level keys).
Constants
DATA_REF_KEYWORDS
Keywords that may hold a `$data` reference instead of a literal value, because the base document schema we have doesn't include those.
private
mixed
DATA_REF_KEYWORDS
= ['multipleOf', 'maximum', 'exclusiveMaximum', 'minimum', 'exclusiveMinimum', 'maxLength', 'minLength', 'pattern', 'maxItems', 'minItems', 'uniqueItems', 'maxProperties', 'minProperties', 'required', 'enum', 'format']
FORMAT_LIMIT_KEYWORDS
Date comparison keywords shared with ajv-formats.
private
mixed
FORMAT_LIMIT_KEYWORDS
= ['formatMinimum', 'formatMaximum', 'formatExclusiveMinimum', 'formatExclusiveMaximum']
Properties
$meta_schema_json
Meta schema.
private
static string
$meta_schema_json
= ''
Methods
get_field_schema_with_context()
Get the field schema with context.
public
static get_field_schema_with_context(string $field_id, array<string|int, mixed> $field_schema, string $context) : array<string|int, mixed>
Parameters
- $field_id : string
-
The field ID.
- $field_schema : array<string|int, mixed>
-
The field schema.
- $context : string
-
The context.
Return values
array<string|int, mixed> —has_field_schema()
Check if the fields have defined schema.
public
static has_field_schema(array<string|int, mixed> $fields) : bool
Parameters
- $fields : array<string|int, mixed>
-
The fields.
Return values
bool —is_valid_schema()
Validate meta schema for field rules.
public
static is_valid_schema(mixed $rules) : bool|WP_Error
Parameters
- $rules : mixed
-
The rules to validate.
Return values
bool|WP_Error — True if the field options are valid, a WP_Error otherwise.validate_document_object()
Validate the field rules.
public
static validate_document_object(DocumentObject $document_object, array<string|int, mixed> $rules) : bool|WP_Error
Parameters
- $document_object : DocumentObject
-
The document object to validate.
- $rules : array<string|int, mixed>
-
The rules to validate against.
Return values
bool|WP_Error —build_meta_schema()
Adds $data references and date comparisons to the draft-07 meta schema.
private
static build_meta_schema() : string
Return values
string — The meta schema as JSON.format_schema_error()
Describes schema errors at the failing keyword instead of the outer schema wrapper.
private
static format_schema_error(ValidationError $error) : string
Parameters
- $error : ValidationError
-
The schema validation error.
Return values
string — The error paths and messages.schema_is_unwrapped()
Check if the schema is unwrapped (has cart, checkout, customer, as top level keys).
private
static schema_is_unwrapped(array<string|int, mixed> $schema) : bool
Parameters
- $schema : array<string|int, mixed>
-
The schema to check.
