PHP Класс Garden\Schema

Наследование: implements JsonSerializable
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$description string
$schema
$types
$validationBehavior integer
$validators An array of callbacks that will custom validate the schema.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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

addValidator() публичный Метод

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.
Результат Schema Returns `$this` for fluent calls.

create() публичный статический Метод

Create a new schema and return it.
public static create ( array $schema = [] ) : Schema
$schema array The schema array.
Результат Schema Returns the newly created and parsed schema.

dumpSpec() публичный Метод

Build an OpenAPI-compatible specification of the current schema.
public dumpSpec ( ) : array
Результат array

filterData() защищенный Метод

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.
Результат Schema Returns the current instance for fluent calls.

getDescription() публичный Метод

Grab the schema's current description.
public getDescription ( ) : string
Результат string

getValidationBehavior() публичный Метод

Return a Schema::VALIDATE_* constant representing the currently configured validation behavior.
public getValidationBehavior ( ) : integer
Результат integer Returns a Schema::VALIDATE_* constant to indicate this instance's validation behavior.

isValid() публичный Метод

Validate data against the schema and return the result.
public isValid ( array &$data, Validation &$validation = null ) : boolean
$data array
$validation Validation
Результат boolean Returns true if the data is valid. False otherwise.

isValidInternal() защищенный Метод

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.
Результат boolean Returns true if the data is valid. False otherwise.

jsonSerialize() публичный Метод

Specify data which should be serialized to JSON.
public jsonSerialize ( ) : mixed
Результат mixed data which can be serialized by json_encode, which is a value of any type other than a resource.

parseSchema() публичный статический Метод

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.
Результат array The full schema array.

parseShortParam() публичный статический Метод

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.
Результат array Returns an array in the form [name, [param]].

requireOneOf() публичный Метод

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.
Результат Schema Returns `$this` for fluent calls.

setDescription() публичный Метод

Set the description for the schema.
public setDescription ( string $description ) : Schema
$description string
Результат Schema

setValidationBehavior() публичный Метод

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.
Результат Schema Returns the current instance for fluent calls.

validate() публичный Метод

Validate data against the schema.
public validate ( array &$data, Validation &$validation = null ) : boolean
$data array
$validation Validation
Результат boolean Returns true if the data is valid, false otherwise.

validateArray() защищенный Метод

Validate an array.
protected validateArray ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateBase64() защищенный Метод

Validate a base64 string.
protected validateBase64 ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateBoolean() защищенный Метод

Validate a boolean value.
protected validateBoolean ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateDatetime() защищенный Метод

Validate a date time.
protected validateDatetime ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateField() защищенный Метод

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.
Результат boolean Returns true if the field is valid, false otherwise.

validateFloat() защищенный Метод

Validate a float.
protected validateFloat ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateInteger() защищенный Метод

Validate and integer.
protected validateInteger ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateObject() защищенный Метод

Validate an object.
protected validateObject ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateRequired() защищенный Метод

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.
Результат 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() защищенный Метод

Validate a string.
protected validateString ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

validateTimestamp() защищенный Метод

Validate a unix timestamp.
protected validateTimestamp ( &$value, array $field, Validation $validation ) : boolean
$field array The field definition.
$validation Validation The validation results to add.
Результат boolean Returns true if {@link $value} is valid or false otherwise.

Описание свойств

$description защищенное свойство

protected string $description
Результат string

$schema защищенное свойство

protected $schema

$types защищенное статическое свойство

protected static $types

$validationBehavior защищенное свойство

protected int $validationBehavior
Результат integer

$validators защищенное свойство

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