Download the PHP package rasuvaeff/yii3-respect-validation without Composer
On this page you can find all versions of the php package rasuvaeff/yii3-respect-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download rasuvaeff/yii3-respect-validation
More information about rasuvaeff/yii3-respect-validation
Files in rasuvaeff/yii3-respect-validation
Package yii3-respect-validation
Short Description Bridge exposing Respect/Validation rules as native yiisoft/validator rules for Yii3 applications
License BSD-3-Clause
Homepage https://github.com/rasuvaeff/yii3-respect-validation
Informations about the package yii3-respect-validation
rasuvaeff/yii3-respect-validation
Bridge exposing Respect/Validation rules as
native yiisoft/validator rules — usable as a #[RespectRule] attribute on a
FormModel/DTO property, alongside built-in Yii3 rules, with results going through
the same Result/Yiisoft\Translator pipeline.
Using an AI coding assistant? llms.txt contains a compact API reference you can share with the model. Contributors: see AGENTS.md.
Requirements
| Requirement | Version |
|---|---|
| PHP | >=8.5 (required by respect/validation ^3.1) |
respect/validation |
^3.1 |
yiisoft/validator |
^2.6 |
yiisoft/translator |
^3.0 |
Installation
Usage
v:: fluent chains work too, since RespectRule accepts either a
Respect\Validation\Validator instance or a Respect\Validation\ValidatorBuilder
(what v:: returns):
PHP attribute arguments must be constant expressions, so only rule chains built from
new Validator(...)calls work directly in#[RespectRule(...)].v::chains need to be built outside the attribute and passed to the constructor.
Fluent v:: chains on a model: RulesProviderInterface
To keep the fluent v:: API without giving up per-model rule declarations,
implement Yiisoft\Validator\RulesProviderInterface instead of attributes —
getRules() is ordinary runtime code, so any chain works there:
Both styles produce identical results and can be mixed: attributes for simple
new-constructible chains, getRules() where the fluent builder is worth it.
Skip / conditional validation
RespectRule implements the same SkipOnEmptyInterface / SkipOnErrorInterface /
WhenInterface contracts as built-in rules:
Messages and translation
Respect's own message templates (e.g. {{subject}} must be a string) are rendered
by the handler itself — not by Respect's internal InterpolationRenderer (which
needs symfony/translation-contracts) — so the whole app keeps a single i18n
pipeline: Yiisoft\Translator.
By default (no TranslatorInterface wired), messages are rendered in English via
RespectMessageFormatter.
A complete Russian catalog ships with the package (messages/ru/, all ~310
Respect template strings). To activate it, install the PHP message reader and set
the application locale to ru — the shipped config/di.php picks it up
automatically:
A build-time test (RussianMessageCatalogTest) pins every catalog key to the
installed respect/validation templates, so an upstream wording change turns CI
red instead of silently dropping translations.
For other locales, add your own catalog next to the app (same category):
DI configuration (Yii3)
This package ships config/di.php + config/params.php via config-plugin —
installing it alongside yiisoft/config is enough to get RespectRuleHandler
wired with a dedicated translation category (yii3-respect-validation) using a
{{placeholder}}-aware RespectMessageFormatter (Respect templates use double
braces, not the ICU syntax the rest of yiisoft/validator uses — mixing the two
under one formatter would break placeholder substitution for one of them).
The category reads the bundled messages/{locale} catalogs when
yiisoft/translator-message-php is installed; without it, messages pass through
untranslated (English template text).
Override the category name in your application config if needed:
Components
RespectRule
| Parameter | Type | Default | Description |
|---|---|---|---|
validator |
Respect\Validation\Validator\|Respect\Validation\ValidatorBuilder |
— | The wrapped Respect rule/chain. |
skipOnEmpty |
bool\|callable\|null |
null |
Skip on empty, see SkipOnEmptyInterface. |
skipOnError |
bool |
false |
Skip on prior error, see SkipOnErrorInterface. |
when |
?Closure |
null |
Conditional execution, see WhenInterface. |
getOptions() (for frontend/client-side metadata export, per
DumpedRuleInterface) returns the wrapped validator's own $parameters property
when present (e.g. Between exposes minValue/maxValue — the same values
Respect uses to fill in its own templates), plus skipOnEmpty/skipOnError.
No JavaScript runtime is shipped — Respect has ~150 rules, many encoding
arbitrary PHP logic (Luhn checksums, locale-aware checks, Callback closures);
porting all of them to JS is not realistic to maintain, so this package limits
itself to the same metadata-export mechanism yiisoft/validator itself uses.
RespectRuleHandler
| Parameter | Type | Default | Description |
|---|---|---|---|
translator |
?Yiisoft\Translator\TranslatorInterface |
null |
If null, falls back to RespectMessageFormatter directly (English only). |
translationCategory |
string |
'yii3-respect-validation' |
Category looked up on $translator. |
Walks the Respect\Validation\Result tree returned by evaluate() and emits one
Yiisoft\Validator\Result error per failed leaf (and per failed adjacent
message), each with its own valuePath built from Respect's own nested Path
(e.g. failing array keys under Each/KeySet).
RespectMessageFormatter
Yiisoft\Translator\MessageFormatterInterface implementation substituting
Respect's own {{param}} placeholder syntax (not ICU). Register it on a
Yiisoft\Translator\CategorySource — see DI configuration.
Security
- No user input is ever interpolated into anything executed — this package only
moves data between two validation result structures (Respect's
Resulttree and Yii3'sResult); it performs no I/O, SQL, or shell access itself. RespectMessageFormatteronly does{{key}}string substitution (strtr()) — nevereval/preg_replacewith the/emodifier or similar.
Examples
See examples/ for a runnable script.
| Script | Shows | Needs server? |
|---|---|---|
validate-form.php |
Wrapping Respect rules on a DTO, reading Result errors |
no |
Development
No PHP/Composer on the host — run in Docker via the composer:2 image:
Or with Make:
CI runs composer build on PHP 8.5 only — respect/validation requires
php: >=8.5, so the usual 8.3/8.4/8.5 matrix does not apply to this package.
License
BSD-3-Clause
All versions of yii3-respect-validation with dependencies
respect/validation Version ^3.1
yiisoft/translator Version ^3.0
yiisoft/validator Version ^2.6