Download the PHP package mb4it/validation without Composer
On this page you can find all versions of the php package mb4it/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mb4it/validation
More information about mb4it/validation
Files in mb4it/validation
Package validation
Short Description Framework-agnostic validation with flexible rules and translation
License MIT
Homepage https://github.com/mb4it/validation
Informations about the package validation
MB Validation
Русская версия
Framework-agnostic validation library inspired by Laravel-style rules, without coupling to a framework.
Features
- String rules (
required|string|min:3) - Object and closure rules
- Localized messages (
ru/en) - Wildcard array rules (
items.*.name) - Strict handling of unknown string rules (fail-fast)
- Optional file-like validation without requiring
symfony/http-foundation
Installation
symfony/http-foundation is optional.
File-related rules work with file-like objects that expose methods such as:
getSize()getPath()orgetRealPath()guessExtension()getMimeType()
Quick Start
Factory API
Create Factory
Signature:
If MessagesInterface is not provided, factory uses DefaultMessages::create($lang).
One-shot Validation
validate() throws MB\Validation\ValidationException if validation fails.
Strict Mode
Unknown string rules throw InvalidArgumentException by default.
Use backward-compatible mode if needed:
Supported Rule Groups
- Presence / structure:
required,required_if,required_unless,required_array_keys,filled,array,list,boolean - Type:
string,numeric,integer,decimal - Size:
min,max,between,size,digits,digits_between - String:
alpha,alpha_num,alpha_dash,contains,doesnt_contain,starts_with,ends_with,doesnt_start_with,doesnt_end_with,uppercase,lowercase,ascii - Format / network:
email,url,ip,ipv4,ipv6,mac_address,hex_color,uuid,ulid,json - Date / time:
date,date_format,timezone - Set / comparison:
in,not_in,same,different,prohibited,any_of - Database:
exists,unique(requiresPresenceVerifierInterface)
Messages and Localization
Default files:
lang/en/validation.phplang/ru/validation.php
Message resolution order:
- Inline messages passed to
make()/validate() - Validator fallback custom messages
- Translator (
MessagesInterface)
Inline message example:
Validate Object Properties via Trait
Use MB\Validation\Concerns\ValidatesProperties for DTO/value object validation.
Trait behavior:
- collects initialized public/protected/private properties via reflection
- supports wildcard keys (
items.*.name,profile.tags.*) - validates with
Factory::create(lang: $this->validatorLang)
Example
Get Errors with Trait
validate() throws ValidationException:
For non-throwing flow, expose a validator helper in your class:
exists / unique and Presence Verifier
Custom Rules
Closure Rule
Class-based Rule
Implement MB\Validation\Contracts\ValidationRule and register your alias in rule registry.
Testing
or
License
MIT (see LICENSE).
All versions of validation with dependencies
mb4it/stringable Version ^1
mb4it/collections Version ^1
mb4it/messages Version ^1.0
psr/container Version ^2.0
brick/math Version ^0.14.8
egulias/email-validator Version ^4.0