Neuron-PHP

IValidator

Core validator interface for the Neuron validation system.

This interface defines the contract that all validators must implement within the Neuron validation framework. It provides a consistent API for validating data across different types and validation rules, enabling composable and reusable validation logic throughout applications.

Key features:

  • Simple boolean validation result for easy integration
  • Support for any data type through mixed parameter
  • Foundation for complex validation rule composition
  • Consistent API across 20+ built-in validators
  • Extensible for custom validation implementations

Common validator implementations:

  • Format validators: IsEmail, IsUrl, IsPhoneNumber, IsJson
  • Type validators: IsString, IsInteger, IsArray, IsBoolean
  • Range validators: IsNumberWithinRange, IsStringLength
  • Pattern validators: IsRegExPattern, IsName
  • Business validators: IsEin, IsUpc, IsCurrency
Tags
example
// Custom validator implementation
class IsPositiveNumber implements IValidator
{
    public function isValid(mixed $value): bool
    {
        return is_numeric($value) && $value > 0;
    }
}

// Usage with validation policies
$policy = new Policy();
$policy->add('amount', new IsPositiveNumber());
$policy->add('email', new IsEmail());

$result = $policy->validate([
    'amount' => 25.99,
    'email' => '[email protected]'
]);

Table of Contents

Methods

isValid()  : bool
Determines if the provided value meets the validity criteria.

Methods

isValid()

Determines if the provided value meets the validity criteria.

public isValid(mixed $value) : bool
Parameters
$value : mixed

The value to be validated.

Return values
bool

Returns true if the value is valid, otherwise false.


        
On this page

Search results