VOOZH about

URL: https://deepwiki.com/hypervel/validation/9-api-reference

⇱ API Reference | hypervel/validation | DeepWiki


Loading...
Menu

API Reference

This document provides complete API documentation for all public classes, interfaces, and methods in the Hypervel Validation package. It serves as a technical reference for developers implementing custom validation rules, integrating validators into applications, or extending the validation framework.

For implementation details of built-in validation rules, see page 3.1. For guidance on creating custom rules, see page 4.2. For configuration and dependency injection setup, see page 5.

Core Framework Contracts

The validation system is built around two primary contracts that define the main entry points for creating and using validators.

Factory Contract

The Factory interface defines how validator instances are created and how custom validation extensions are registered.

src/Contracts/Factory.php9-30

MethodParametersReturn TypePurpose
makearray $data, array $rules, array $messages = [], array $attributes = []ValidatorCreates a new validator instance
extendstring $rule, Closure|string $extension, ?string $message = nullvoidRegisters custom validator extension
extendImplicitstring $rule, Closure|string $extension, ?string $message = nullvoidRegisters implicit validator extension
replacerstring $rule, Closure|string $replacervoidRegisters custom message replacer

Validator Contract

The Validator interface extends MessageProvider and defines the complete validation lifecycle and result access methods.

src/Contracts/Validator.php12-74

MethodParametersReturn TypePurpose
validate-arrayRuns validation, throws on failure
validated-arrayGets validated attributes, throws on failure
fails-boolChecks if validation failed
failed-arrayGets failed validation rules
sometimesarray|string $attribute, array|string $rules, callable $callbackstaticAdds conditional rules
aftercallable|string $callbackstaticAdds after validation callback
errors-MessageBagGets validation error messages
getTranslator-TranslatorGets translator instance
getData-arrayGets data under validation
setDataarray $datastaticSets data under validation
getException-stringGets exception class name

Implementation Classes:

Sources: src/Contracts/Factory.php9-30 src/Contracts/Validator.php12-74

Rule Contracts

The validation system supports multiple types of custom rules through different contracts, each optimized for specific use cases.

Basic Rule Contract

The Rule interface provides the traditional boolean-based validation approach.

src/Contracts/Rule.php7-18

MethodParametersReturn TypePurpose
passesstring $attribute, mixed $valueboolDetermines if validation passes
message-array|stringGets validation error message

ValidationRule Contract

The ValidationRule interface uses a failure closure pattern for more flexible error handling.

src/Contracts/ValidationRule.php9-17

MethodParametersReturn TypePurpose
validatestring $attribute, mixed $value, Closure $failvoidRuns validation with failure callback

The $fail closure signature: Closure(string, ?string=): \Hypervel\Translation\PotentiallyTranslatedString

InvokableRule Contract

The InvokableRule interface allows rules to be called directly as functions.

src/Contracts/InvokableRule.php9-17

MethodParametersReturn TypePurpose
__invokestring $attribute, mixed $value, Closure $failvoidDirect invocation for validation

The $fail closure signature matches ValidationRule for consistency.

ImplicitRule Contract

Rules implementing ImplicitRule are validated even when the attribute is missing from the data.

src/Contracts/ImplicitRule.php

This interface extends Rule but has no additional methods. The marker interface indicates that the rule should execute even for absent attributes (like required, filled, present).

DataAwareRule Contract

Rules implementing DataAwareRule can access the complete validation dataset for cross-field validation.

MethodParametersReturn TypePurpose
setDataarray $datastaticProvides access to all validation data

ValidatorAwareRule Contract

Rules implementing ValidatorAwareRule can access the validator instance for complex validation scenarios.

MethodParametersReturn TypePurpose
setValidatorValidator $validatorstaticProvides access to validator instance

Sources: src/Contracts/Rule.php7-18 src/Contracts/ValidationRule.php9-17 src/Contracts/InvokableRule.php9-17 src/Contracts/ImplicitRule.php src/Contracts/DataAwareRule.php src/Contracts/ValidatorAwareRule.php

Contract Relationship Architecture


Sources: src/Contracts/Factory.php9-30 src/Contracts/Validator.php12-74 src/Contracts/Rule.php7-18 src/Contracts/ValidationRule.php9-17 src/Contracts/InvokableRule.php9-17

Method Signatures and Integration Points

Factory Integration Pattern


Validation Execution Flow


Sources: src/Contracts/Factory.php11-29 src/Contracts/Validator.php14-73

Rule Implementation Patterns

Rule Contract Selection Guide

ContractUse CaseError HandlingInvocation Style
RuleSimple boolean validationReturn string/array from message()Traditional OOP
ValidationRuleComplex validation with contextCall $fail() closureModern closure-based
InvokableRuleFunctional-style rulesCall $fail() closureDirect function call

Closure Signature Reference

Both ValidationRule and InvokableRule use the same failure closure signature:


  • $failureMessage: The validation error message
  • $errorKey: Optional translation key for internationalization
  • Returns: PotentiallyTranslatedString for translation system integration

Extension Registration Methods

MethodRule TypeBehaviorMessage Handling
extendExplicitOnly validates when field is presentCustom message optional
extendImplicitImplicitValidates even when field is missingCustom message optional
replacerMessageCustomizes placeholder replacementN/A - message processing only

Sources: src/Contracts/Rule.php11-17 src/Contracts/ValidationRule.php14-16 src/Contracts/InvokableRule.php14-16 src/Contracts/Factory.php18-29