VOOZH about

URL: https://deepwiki.com/hypervel/validation/8-advanced-features

⇱ Advanced Features | hypervel/validation | DeepWiki


Loading...
Menu

Advanced Features

This page covers advanced capabilities in the Hypervel validation system that extend beyond standard validation rules. These features include dependency injection integration, context-aware rule interfaces, and specialized validation strategies.

For basic validation rules, see Built-in Validation Rules. For creating custom validation logic, see Custom Validation Rules. For database-related validation, see Database Integration.

Dependency Injection Integration

The validation system integrates with Hyperf's dependency injection container through service providers and specialized contracts. This enables automatic validator resolution, lifecycle management, and dependency injection of validation-related services.

ConfigProvider Service Registration

The ConfigProvider class registers validation services with the container, mapping interfaces to concrete implementations. This enables automatic dependency resolution throughout the application.

ConfigProvider Service Registration


Service Bindings:

InterfaceImplementationPurpose
FactoryValidatorFactoryPrimary validator creation
DatabasePresenceVerifierInterfacePresenceVerifierFactoryDatabase validation support
UncompromisedVerifierUncompromisedVerifierFactoryPassword breach detection

Sources: src/ConfigProvider.php1-22

ValidatesWhenResolved Contract

The ValidatesWhenResolved interface enables automatic validation when a class is resolved from the container. This is typically used with form request classes to trigger validation immediately after dependency injection.

ValidatesWhenResolved Lifecycle


The interface defines a single method:

MethodReturn TypePurpose
validateResolved()voidExecute validation after container resolution

This contract enables declarative validation at the dependency injection layer, automatically validating input data when request objects are instantiated.

Sources: src/Contracts/ValidatesWhenResolved.php1-13

Context-Aware Rule Interfaces

The validation system provides specialized interfaces that allow validation rules to access the broader validation context. These interfaces enable rules to examine other data fields or interact with the validator instance itself.

DataAwareRule Interface

The DataAwareRule interface allows rules to access all data being validated, enabling cross-field validation logic. When a rule implements this interface, the validator automatically injects the complete data array before validation execution.

DataAwareRule Data Flow


Interface Definition:

MethodParametersReturnPurpose
setData()array $datastaticInject complete validation data

Common use cases for DataAwareRule:

  • Conditional validation: Rules that depend on other field values
  • Cross-field comparison: Validating one field against another (e.g., password confirmation)
  • Contextual logic: Rules requiring access to the full data context

Sources: src/Contracts/DataAwareRule.php1-13

ValidatorAwareRule Interface

The ValidatorAwareRule interface provides rules with access to the entire validator instance. This enables rules to access validator state, configuration, and methods for complex validation scenarios.

ValidatorAwareRule Integration


Interface Definition:

MethodParametersReturnPurpose
setValidator()Validator $validatorstaticInject validator instance

Use cases for ValidatorAwareRule:

  • Dynamic message generation: Access validator's message formatting capabilities
  • Rule composition: Execute other validation rules programmatically
  • State inspection: Check validation state or previously validated fields
  • Extension access: Utilize custom extensions registered on the validator

Sources: src/Contracts/ValidatorAwareRule.php1-13

Interface Comparison

Context-Aware Rule Interface Comparison


Rules may implement both interfaces to gain access to both the data array and the validator instance. The validator automatically detects these interfaces and injects the appropriate dependencies before rule execution.

Sources: src/Contracts/DataAwareRule.php1-13 src/Contracts/ValidatorAwareRule.php1-13

Email Validation Strategies

The validation system supports multiple email validation strategies beyond the default Egulias EmailValidator integration. The FilterEmailValidation class provides a lightweight alternative using PHP's native filter functions.

FilterEmailValidation Implementation

The FilterEmailValidation class implements the Egulias EmailValidation interface but uses PHP's filter_var() function internally. This provides a performance-optimized alternative for applications that don't require strict RFC compliance.

FilterEmailValidation Architecture


Class Structure:

ComponentTypePurpose
__construct(?int $flags)ConstructorInitialize with optional filter flags
unicode()Static factoryCreate instance with Unicode support
isValid(string, EmailLexer)ValidationExecute filter_var validation
getError()Error handlingReturns null (simplified error model)
getWarnings()Warning handlingReturns empty array

Implementation Details:


Key Features:

  • Performance: Direct use of PHP's native filter functions
  • Unicode Support: FILTER_FLAG_EMAIL_UNICODE flag for international email addresses
  • Simplified Error Handling: No detailed error messages or warnings
  • Egulias Compatibility: Implements standard EmailValidation interface

Usage:

The class provides two construction patterns:

  1. Default validation: new FilterEmailValidation()
  2. Unicode support: FilterEmailValidation::unicode()

The unicode() static factory creates an instance configured with FILTER_FLAG_EMAIL_UNICODE, which allows Unicode characters in the local-part of email addresses (before the @ symbol).

Sources: src/Concerns/FilterEmailValidation.php1-59

Integration Architecture

The advanced features integrate with external services and framework components through well-defined interfaces and dependency injection.

HTTP Client Integration

The NotPwnedVerifier uses the Hypervel HTTP client factory for API communication with configurable timeouts and headers:


HTTP Configuration Options:

SettingDefaultPurpose
timeout30 secondsRequest timeout limit
Add-Padding headertruePrevents response analysis attacks
Error handlingreport() + fallbackGraceful degradation on API failures

Sources: src/NotPwnedVerifier.php67-82

Framework Integration Points

Both advanced features integrate with the Hyperf framework through dependency injection and service configuration:


Sources: src/NotPwnedVerifier.php21-25 src/Concerns/FilterEmailValidation.php18-21