Download the PHP package dsheiko/validate without Composer
On this page you can find all versions of the php package dsheiko/validate. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dsheiko/validate
More information about dsheiko/validate
Files in dsheiko/validate
Package validate
Short Description High-performance, secure validation library for Design by Contract programming. Validate primitive and complex types with chainable validators, contract-based validation, and comprehensive security features.
License MIT
Homepage https://github.com/dsheiko/validate
Informations about the package validate
Dsheiko\Validate
Extendable, high-performance validation library for testing primitive and complex types against a contract. Designed for Design by Contract programming and comprehensive input validation in PHP applications.
- Installation
- Requirements
- Key Features
- Quick Start
- Security
- Performance
- Usage
- Examples
- Contributing
Installation
Require as a composer dependency:
Requirements
- PHP >= 7.0.0
- No external dependencies
Key Features
🎯 Core Capabilities
- Validators are dead simple to extend - Create custom validators by implementing ValidateInterface
- Design by Contract support - Validate preconditions and postconditions with Validate::contract()
- Validator chaining - Chain multiple validators for fluent validation syntax
- Direct assertion access - Use validators as direct assertions in your code
- Complex type validation - Support for nested arrays, associative arrays, and key-value structures
- Exception-based error handling - Specific exception types for different validation failures
🔐 Security Features (v1.2.0+)
- Credit card validation - Implements Luhn algorithm for genuine card validation
- ReDoS protection - Length constraints prevent regular expression denial of service attacks
- Email length validation - RFC 5321 compliant length constraints
- Input sanitization - Validators properly handle edge cases and malicious input
⚡ Performance Features
- Factory caching - 30-50% faster validation chains
- Optimized validators - 10-15% faster UUID and string validation
- Efficient loops - Removed closure overhead for 5-10% improvement
- Minimal overhead - Fast validation suitable for high-traffic applications
Quick Start
Security
Recent Security Improvements (v1.2.0)
This library has been updated with critical security fixes:
-
Credit Card Validation - Now implements the Luhn algorithm to properly validate credit card numbers. Invalid cards that previously passed regex validation will now be correctly rejected.
-
ReDoS Protection - Added length constraints and optimized regex patterns to prevent Regular Expression Denial of Service attacks.
- Email Validation - Enforces RFC 5321 email length constraints (maximum 254 characters) to prevent DoS attacks.
See CHANGELOG.md for detailed security fixes in v1.2.0.
Best Practices
- Always validate user input - Use this library to validate all untrusted input
- Use contract validation - Catch errors early with Design by Contract validation
- Validate early - Validate input at the application boundary
- Handle exceptions - Catch and properly handle validation exceptions
Performance
Benchmarks (v1.2.0)
The library has been optimized for high-performance validation:
- Validation chains: 30-50% faster with factory caching
- UUID validation: 10-15% faster with pre-checks
- Contract validation: 5-10% faster with optimized loops
- Factory calls (1000x): 0.14ms
Performance Tips
- Use validation contracts for bulk validation
- Chain multiple validators instead of separate checks
- Validate at the boundary of your application
- Consider using map validation for complex data structures
See CHANGELOG.md for performance improvement details in v1.2.0.
Usage
- Basic Usage
- Provided Validators
- Validator Chain
- Validation by Contract
- Map Validation
- Custom Validators
Examples
Design by Contract Validation
Potential exceptions:
Dsheiko\Validate\IsEmailAddress\ExceptionDsheiko\Validate\IsString\ExceptionDsheiko\Validate\IsString\MinLength\ExceptionDsheiko\Validate\IsString\MaxLength\Exception
Error messages:
Parameter "email" validation failed: "[email protected] not a valid email addressParameter "password" validation failed: "123" is too short; must be more than 6 chars
Map Validation
Exception messages:
Property "email" validation failed: "invalid.." is not a valid email addressProperty "age" validation failed: 200 is too high; must be less than 150
Validator Chaining
Available Validators
Core validators included:
IsString- Validates string type with length constraintsIsInt- Validates integer type with min/max constraintsIsBool- Validates boolean typeIsArray- Validates array typeIsAssocArray- Validates associative array typeIsEmailAddress- Validates email address (RFC 5321 compliant)IsUrl- Validates URL formatIsUuid- Validates UUID v4 formatIsIp- Validates IPv4 and IPv6 addressesIsAlpha- Validates alphabetic characters onlyIsAlnum- Validates alphanumeric charactersIsCreditCard- Validates credit card number with Luhn algorithmNotEmpty- Validates non-empty values
License
MIT License - see LICENSE file for details