Property | Type | Description | |
---|---|---|---|
$description | string | ||
$schema | |||
$types | |||
$validationBehavior | integer | ||
$validators | An array of callbacks that will custom validate the schema. |
Method | Description | |
---|---|---|
__construct ( array $schema = [] ) | Initialize an instance of a new {@link Schema} class. | |
addValidator ( string $fieldname, callable $callback ) : |
Add a custom validator to to validate the schema. | |
create ( array $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, |
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 ) : |
Require one of a given set of fields in the schema. | |
setDescription ( string $description ) : |
Set the description for the schema. | |
setValidationBehavior ( integer $validationBehavior ) : |
Set the validation behavior for the schema, which determines how invalid properties are handled. | |
validate ( array &$data, |
Validate data against the schema. |
Method | Description | |
---|---|---|
filterData ( array &$data, array $schema, |
Filter fields not in the schema. The action taken is determined by the configured validation behavior. | |
isValidInternal ( array &$data, array $schema, |
Validate data against the schema and return the result. | |
validateArray ( &$value, array $field, |
Validate an array. | |
validateBase64 ( &$value, array $field, |
Validate a base64 string. | |
validateBoolean ( &$value, array $field, |
Validate a boolean value. | |
validateDatetime ( &$value, array $field, |
Validate a date time. | |
validateField ( &$value, array $field, |
Validate a field. | |
validateFloat ( &$value, array $field, |
Validate a float. | |
validateInteger ( &$value, array $field, |
Validate and integer. | |
validateObject ( &$value, array $field, |
Validate an object. | |
validateRequired ( &$value, array $field, |
Validate a required field. | |
validateString ( &$value, array $field, |
Validate a string. | |
validateTimestamp ( &$value, array $field, |
Validate a unix timestamp. |
Method | 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. |
public __construct ( array $schema = [] ) | ||
$schema | array | The array schema to validate against. |
public addValidator ( string $fieldname, callable $callback ) : |
||
$fieldname | string | The name of the field to validate, if any. |
$callback | callable | The callback to validate with. |
return | Returns `$this` for fluent calls. |
protected filterData ( array &$data, array $schema, |
||
$data | array | |
$schema | array | The schema array. Its configured parameters are used to filter $data. |
$validation | ||
$path | string | The path to current parameters for nested objects. |
return | Returns the current instance for fluent calls. |
public getDescription ( ) : string | ||
return | string |
public getValidationBehavior ( ) : integer | ||
return | integer | Returns a Schema::VALIDATE_* constant to indicate this instance's validation behavior. |
protected isValidInternal ( array &$data, array $schema, |
||
$data | array | |
$schema | array | The schema array to validate against. |
$validation | ||
$path | string | The path to the current path for nested objects. |
return | boolean | Returns true if the data is valid. False otherwise. |
public jsonSerialize ( ) : mixed | ||
return | mixed | data which can be serialized by json_encode, which is a value of any type other than a resource. |
public static parseSchema ( array $arr ) : array | ||
$arr | array | The array to parse into a schema. |
return | array | The full schema array. |
public requireOneOf ( array $fieldnames, integer $count = 1 ) : |
||
$fieldnames | array | The field names to require. |
$count | integer | The count of required items. |
return | Returns `$this` for fluent calls. |
public setDescription ( string $description ) : |
||
$description | string | |
return |
public setValidationBehavior ( integer $validationBehavior ) : |
||
$validationBehavior | integer | One of the Schema::VALIDATE_* constants. |
return | Returns the current instance for fluent calls. |
protected validateArray ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateBase64 ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateBoolean ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateDatetime ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateField ( &$value, array $field, |
||
$field | array | Parameters on the field. |
$validation | A validation object to add errors to. | |
return | boolean | Returns true if the field is valid, false otherwise. |
protected validateFloat ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateInteger ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateObject ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateRequired ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | A {@link Validation} object to collect errors. | |
return | 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. |
protected validateString ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |
protected validateTimestamp ( &$value, array $field, |
||
$field | array | The field definition. |
$validation | The validation results to add. | |
return | boolean | Returns true if {@link $value} is valid or false otherwise. |