PHP Class Garden\Schema

Inheritance: implements JsonSerializable
Afficher le fichier Open project: vanilla/vanilla

Protected Properties

Свойство Type Description
$description string
$schema
$types
$validationBehavior integer
$validators An array of callbacks that will custom validate the schema.

Méthodes publiques

Méthode Description
__construct ( array $schema = [] ) Initialize an instance of a new {@link Schema} class.
addValidator ( string $fieldname, callable $callback ) : Schema Add a custom validator to to validate the schema.
create ( array $schema = [] ) : Schema Create a new schema and return it.
dumpSpec ( ) : array Build an OpenAPI-compatible specification of the current schema.
getDescription ( ) : string Grab the schema's current description.
getValidationBehavior ( ) : integer Return a Schema::VALIDATE_* constant representing the currently configured validation behavior.
isValid ( array &$data, Validation &$validation = null ) : boolean Validate data against the schema and return the result.
jsonSerialize ( ) : mixed Specify data which should be serialized to JSON.
parseSchema ( array $arr ) : array Parse a schema in short form into a full schema array.
parseShortParam ( string $str, array $other = [] ) : array Parse a short parameter string into a full array parameter.
requireOneOf ( array $fieldnames, integer $count = 1 ) : Schema Require one of a given set of fields in the schema.
setDescription ( string $description ) : Schema Set the description for the schema.
setValidationBehavior ( integer $validationBehavior ) : Schema Set the validation behavior for the schema, which determines how invalid properties are handled.
validate ( array &$data, Validation &$validation = null ) : boolean Validate data against the schema.

Méthodes protégées

Méthode Description
filterData ( array &$data, array $schema, Validation &$validation, string $path = '' ) : Schema Filter fields not in the schema. The action taken is determined by the configured validation behavior.
isValidInternal ( array &$data, array $schema, Validation &$validation = null, string $path = '' ) : boolean Validate data against the schema and return the result.
validateArray ( &$value, array $field, Validation $validation ) : boolean Validate an array.
validateBase64 ( &$value, array $field, Validation $validation ) : boolean Validate a base64 string.
validateBoolean ( &$value, array $field, Validation $validation ) : boolean Validate a boolean value.
validateDatetime ( &$value, array $field, Validation $validation ) : boolean Validate a date time.
validateField ( &$value, array $field, Validation $validation ) : boolean Validate a field.
validateFloat ( &$value, array $field, Validation $validation ) : boolean Validate a float.
validateInteger ( &$value, array $field, Validation $validation ) : boolean Validate and integer.
validateObject ( &$value, array $field, Validation $validation ) : boolean Validate an object.
validateRequired ( &$value, array $field, Validation $validation ) : boolean | null Validate a required field.
validateString ( &$value, array $field, Validation $validation ) : boolean Validate a string.
validateTimestamp ( &$value, array $field, Validation $validation ) : boolean Validate a unix timestamp.

Private Methods

Méthode Description
arraySelect ( array $keys, array $array, mixed $default = null ) : mixed Select the first non-empty value from an array.
strEnds ( string $haystack, string $needle ) : boolean Returns whether or not a string ends with another string.

Method Details

__construct() public méthode

Initialize an instance of a new {@link Schema} class.
public __construct ( array $schema = [] )
$schema array The array schema to validate against.

addValidator() public méthode

Add a custom validator to to validate the schema.
public addValidator ( string $fieldname, callable $callback ) : Schema
$fieldname string The name of the field to validate, if any.
$callback callable The callback to validate with.
Résultat Schema Returns `$this` for fluent calls.

create() public static méthode

Create a new schema and return it.
public static create ( array $schema = [] ) : Schema
$schema array The schema array.
Résultat Schema Returns the newly created and parsed schema.

dumpSpec() public méthode

Build an OpenAPI-compatible specification of the current schema.
public dumpSpec ( ) : array
Résultat array

filterData() protected méthode

Filter fields not in the schema. The action taken is determined by the configured validation behavior.
protected filterData ( array &$data, array $schema, Validation &$validation, string $path = '' ) : Schema
$data array
$schema array The schema array. Its configured parameters are used to filter $data.
$validation Validation
$path string The path to current parameters for nested objects.
Résultat Schema Returns the current instance for fluent calls.

getDescription() public méthode

Grab the schema's current description.
public getDescription ( ) : string
Résultat string

getValidationBehavior() public méthode

Return a Schema::VALIDATE_* constant representing the currently configured validation behavior.
public getValidationBehavior ( ) : integer
Résultat integer Returns a Schema::VALIDATE_* constant to indicate this instance's validation behavior.

isValid() public méthode

Validate data against the schema and return the result.
public isValid ( array &$data, Validation &$validation = null ) : boolean
$data array
$validation Validation
Résultat boolean Returns true if the data is valid. False otherwise.

isValidInternal() protected méthode

Validate data against the schema and return the result.
protected isValidInternal ( array &$data, array $schema, Validation &$validation = null, string $path = '' ) : boolean
$data array
$schema array The schema array to validate against.
$validation Validation
$path string The path to the current path for nested objects.
Résultat boolean Returns true if the data is valid. False otherwise.

jsonSerialize() public méthode

Specify data which should be serialized to JSON.
public jsonSerialize ( ) : mixed
Résultat mixed data which can be serialized by json_encode, which is a value of any type other than a resource.

parseSchema() public static méthode

Parse a schema in short form into a full schema array.
public static parseSchema ( array $arr ) : array
$arr array The array to parse into a schema.
Résultat array The full schema array.

parseShortParam() public static méthode

Parse a short parameter string into a full array parameter.
public static parseShortParam ( string $str, array $other = [] ) : array
$str string The short parameter string to parse.
$other array An array of other information that might help resolve ambiguity.
Résultat array Returns an array in the form [name, [param]].

requireOneOf() public méthode

Require one of a given set of fields in the schema.
public requireOneOf ( array $fieldnames, integer $count = 1 ) : Schema
$fieldnames array The field names to require.
$count integer The count of required items.
Résultat Schema Returns `$this` for fluent calls.

setDescription() public méthode

Set the description for the schema.
public setDescription ( string $description ) : Schema
$description string
Résultat Schema

setValidationBehavior() public méthode

Set the validation behavior for the schema, which determines how invalid properties are handled.
public setValidationBehavior ( integer $validationBehavior ) : Schema
$validationBehavior integer One of the Schema::VALIDATE_* constants.
Résultat Schema Returns the current instance for fluent calls.

validate() public méthode

Validate data against the schema.
public validate ( array &$data, Validation &$validation = null ) : boolean
$data array
$validation Validation
Résultat boolean Returns true if the data is valid, false otherwise.

validateArray() protected méthode

Validate an array.
protected validateArray ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateBase64() protected méthode

Validate a base64 string.
protected validateBase64 ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateBoolean() protected méthode

Validate a boolean value.
protected validateBoolean ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateDatetime() protected méthode

Validate a date time.
protected validateDatetime ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateField() protected méthode

Validate a field.
protected validateField ( &$value, array $field, Validation $validation ) : boolean
$field array Parameters on the field.
$validation Validation A validation object to add errors to.
Résultat boolean Returns true if the field is valid, false otherwise.

validateFloat() protected méthode

Validate a float.
protected validateFloat ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateInteger() protected méthode

Validate and integer.
protected validateInteger ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateObject() protected méthode

Validate an object.
protected validateObject ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateRequired() protected méthode

Validate a required field.
protected validateRequired ( &$value, array $field, Validation $validation ) : boolean | null
$field array The field definition.
$validation Validation A {@link Validation} object to collect errors.
Résultat boolean | null Returns one of the following: - null: The field is not required. - true: The field is required and {@link $value} is not empty. - false: The field is required and {@link $value} is empty.

validateString() protected méthode

Validate a string.
protected validateString ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

validateTimestamp() protected méthode

Validate a unix timestamp.
protected validateTimestamp ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Résultat boolean Returns true if {@link $value} is valid or false otherwise.

Property Details

$description protected_oe property

protected string $description
Résultat string

$schema protected_oe property

protected $schema

$types protected_oe static_oe property

protected static $types

$validationBehavior protected_oe property

protected int $validationBehavior
Résultat integer

$validators protected_oe property

An array of callbacks that will custom validate the schema.
protected $validators