Indura API

Scheme
in package

Class to define data validation schemes for use in database models or responses.

A validation class that validates data against a defined set of rules. Provides built-in validation rules for common data types and constraints, and allows custom rule registration.

Table of Contents

Properties

$errors  : mixed
$ruleMethods  : mixed
$scheme  : mixed

Methods

__construct()  : mixed
Constructor
addRule()  : void
Registers a custom validation rule
customValidation()  : string|null
Executes a custom validation rule
getErrors()  : array<string|int, mixed>
Gets all validation errors
hasErrors()  : bool
Checks if there are any validation errors
validate()  : array<string|int, mixed>
Validates data against the defined scheme
validateBoolean()  : string|null
Validates that a field is a boolean value
validateDict()  : string|null
Validates that a field is an associative array (dictionary)
validateEmail()  : string|null
Validates that a field is a valid email address
validateExcluded()  : string|null
Validates that a field is not present or empty
validateExcludedIn()  : string|null
Validates that a field value is not within a list of excluded values
validateFloat()  : string|null
Validates that a field is a float/decimal number
validateIn()  : string|null
Validates that a field value is within a list of allowed values
validateInteger()  : string|null
Validates that a field is an integer
validateMax()  : string|null
Validates maximum value, length, or array size
validateMin()  : string|null
Validates minimum value, length, or array size
validateRequired()  : string|null
Validates that a field is present and not empty
validateRequiredIn()  : string|null
Validates that a field is required when another field has a specific value
validateString()  : string|null
Validates that a field is a string
validateUniqueIn()  : string|null
Validates that a field value is unique and does not exist in another field's array

Properties

$errors

private mixed $errors = []

$ruleMethods

private mixed $ruleMethods = ['required' => 'validateRequired', 'excluded' => 'validateExcluded', 'email' => 'validateEmail', 'string' => 'validateString', 'integer' => 'validateInteger', 'float' => 'validateFloat', 'boolean' => 'validateBoolean', 'in' => 'validateIn', 'excluded_in' => 'validateExcludedIn', 'unique-in' => 'validateUniqueIn', 'required-in' => 'validateRequiredIn', 'dict' => 'validateDict', 'min' => 'validateMin', 'max' => 'validateMax']

Methods

__construct()

Constructor

public __construct(array<string|int, mixed> $scheme) : mixed
Parameters
$scheme : array<string|int, mixed>

Associative array where keys are field names and values are arrays of validation rules

addRule()

Registers a custom validation rule

public addRule(string $ruleName, callable $callback) : void
Parameters
$ruleName : string

The name of the custom rule

$callback : callable

The validation callback function

customValidation()

Executes a custom validation rule

public customValidation(string $ruleName, mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$ruleName : string

The name of the rule to execute

$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters for the rule

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

getErrors()

Gets all validation errors

public getErrors() : array<string|int, mixed>
Return values
array<string|int, mixed>

Array of validation errors

hasErrors()

Checks if there are any validation errors

public hasErrors() : bool
Return values
bool

True if errors exist, false otherwise

validate()

Validates data against the defined scheme

public validate(array<string|int, mixed> $data) : array<string|int, mixed>
Parameters
$data : array<string|int, mixed>

The data to validate

Return values
array<string|int, mixed>

Array of validation errors, empty if validation passes

validateBoolean()

Validates that a field is a boolean value

private validateBoolean(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateDict()

Validates that a field is an associative array (dictionary)

private validateDict(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateEmail()

Validates that a field is a valid email address

private validateEmail(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateExcluded()

Validates that a field is not present or empty

private validateExcluded(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateExcludedIn()

Validates that a field value is not within a list of excluded values

private validateExcludedIn(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array of excluded values

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateFloat()

Validates that a field is a float/decimal number

private validateFloat(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateIn()

Validates that a field value is within a list of allowed values

private validateIn(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array of allowed values

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateInteger()

Validates that a field is an integer

private validateInteger(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateMax()

Validates maximum value, length, or array size

private validateMax(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array containing the maximum value

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateMin()

Validates minimum value, length, or array size

private validateMin(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array containing the minimum value

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateRequired()

Validates that a field is present and not empty

private validateRequired(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateRequiredIn()

Validates that a field is required when another field has a specific value

private validateRequiredIn(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array containing [dependent field name, dependent field value]

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateString()

Validates that a field is a string

private validateString(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Additional parameters (unused)

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid

validateUniqueIn()

Validates that a field value is unique and does not exist in another field's array

private validateUniqueIn(mixed $value, string $fieldName, array<string|int, mixed> $params, array<string|int, mixed> $data) : string|null
Parameters
$value : mixed

The value to validate

$fieldName : string

The name of the field

$params : array<string|int, mixed>

Array containing the name of the field to check against

$data : array<string|int, mixed>

The full data array

Return values
string|null

Error message or null if valid


        
On this page

Search results