Download the PHP package kariricode/validator without Composer
On this page you can find all versions of the php package kariricode/validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kariricode/validator
More information about kariricode/validator
Files in kariricode/validator
Package validator
Short Description A robust and flexible data sanitization component for PHP, part of the KaririCode Framework, utilizing configurable processors and native functions.
License MIT
Homepage https://kariricode.org
Informations about the package validator
KaririCode Framework: Validator Component
A powerful and flexible data validation component for PHP, part of the KaririCode Framework. It uses attribute-based validation with configurable processors to ensure data integrity and validation in your applications.
Table of Contents
- Features
- Installation
- Usage
- Basic Usage
- Advanced Usage: User Registration
- Available Validators
- Input Validators
- Numeric Validators
- Logic Validators
- Date Validators
- Configuration
- Integration with Other KaririCode Components
- Development and Testing
- Contributing
- License
- Support and Community
Features
- Attribute-based validation for object properties
- Comprehensive set of built-in validators for common use cases
- Easy integration with other KaririCode components
- Configurable processors for customized validation logic
- Support for custom error messages
- Extensible architecture allowing custom validators
- Robust error handling and reporting
- Chainable validation pipelines for complex data validation
- Built-in support for multiple validation scenarios
- Type-safe validation with PHP 8.3 features
Installation
You can install the Validator component via Composer:
Requirements
- PHP 8.3 or higher
- Composer
- Extensions:
ext-mbstring
,ext-filter
Usage
Basic Usage
-
Define your data class with validation attributes:
- Set up the validator and use it:
Advanced Usage: User Registration
Here's an example of how to use the KaririCode Validator in a real-world scenario, such as validating user registration data:
Available Validators
Input Validators
-
EmailValidator: Validates email addresses using PHP's filter_var function.
- Error Keys:
invalidType
: Input is not a stringinvalidFormat
: Invalid email format
-
LengthValidator: Validates string length within specified bounds.
- Configuration Options:
minLength
: Minimum allowed lengthmaxLength
: Maximum allowed length- Error Keys:
invalidType
: Input is not a stringtooShort
: String is shorter than minLengthtooLong
: String is longer than maxLength
- UrlValidator: Validates URLs using PHP's filter_var function.
- Error Keys:
invalidType
: Input is not a stringinvalidFormat
: Invalid URL format
Numeric Validators
-
IntegerValidator: Ensures the input is a valid integer.
- Error Keys:
notAnInteger
: Input is not a valid integer
- RangeValidator: Validates numeric values within a specified range.
- Configuration Options:
min
: Minimum allowed valuemax
: Maximum allowed value- Error Keys:
notNumeric
: Input is not a numberoutOfRange
: Value is outside specified range
Logic Validators
- RequiredValidator: Ensures a value is not empty.
- Error Keys:
missingValue
: Required value is missing or empty
Date Validators
-
DateFormatValidator: Validates dates against a specified format.
- Configuration Options:
format
: Date format string (default: 'Y-m-d')- Error Keys:
invalidType
: Input is not a stringinvalidFormat
: Date doesn't match specified format
- DateRangeValidator: Validates dates within a specified range.
- Configuration Options:
minDate
: Minimum allowed datemaxDate
: Maximum allowed dateformat
: Date format string (default: 'Y-m-d')- Error Keys:
invalidType
: Input is not a stringinvalidDate
: Invalid date formatoutOfRange
: Date is outside specified range
Configuration
The Validator component can be configured globally or per-validator basis. Here's an example of how to configure the LengthValidator
:
Integration with Other KaririCode Components
The Validator component is designed to work seamlessly with other KaririCode components:
- KaririCode\Contract: Provides interfaces and contracts for consistent component integration.
- KaririCode\ProcessorPipeline: Utilized for building and executing validation pipelines.
- KaririCode\PropertyInspector: Used for analyzing and processing object properties with validation attributes.
Registry Explanation
The registry is a central component for managing validators. Here's how to set up a complete registry:
Development and Testing
For development and testing purposes, this package uses Docker and Docker Compose to ensure consistency across different environments. A Makefile is provided for convenience.
Prerequisites
- Docker
- Docker Compose
- Make (optional, but recommended for easier command execution)
Development Setup
-
Clone the repository:
-
Set up the environment:
-
Start the Docker containers:
- Install dependencies:
Available Make Commands
make up
: Start all services in the backgroundmake down
: Stop and remove all containersmake build
: Build Docker imagesmake shell
: Access the PHP container shellmake test
: Run testsmake coverage
: Run test coverage with visual formattingmake cs-fix
: Run PHP CS Fixer to fix code stylemake quality
: Run all quality commands (cs-check, test, security-check)
Contributing
We welcome contributions to the KaririCode Validator component! Here's how you can contribute:
- Fork the repository
- Create a new branch for your feature or bug fix
- Write tests for your changes
- Implement your changes
- Run the test suite and ensure all tests pass
- Submit a pull request with a clear description of your changes
Please read our Contributing Guide for more details on our code of conduct and development process.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support and Community
- Documentation: https://kariricode.org/docs/validator
- Issue Tracker: GitHub Issues
- Community Forum: KaririCode Club Community
- Stack Overflow: Tag your questions with
kariricode-validator
Built with ❤️ by the KaririCode team. Empowering developers to create more secure and robust PHP applications.
All versions of validator with dependencies
kariricode/contract Version ^2.7
kariricode/processor-pipeline Version ^1.1
kariricode/property-inspector Version ^1.0
kariricode/exception Version ^1.0