preflow / validation
Preflow validation — rule engine, built-in rules, error bags
Requires
- php: >=8.4
- ext-mbstring: *
- preflow/i18n: ^0.37 || @dev
- preflow/view: ^0.1 || @dev
Requires (Dev)
- phpunit/phpunit: ^11.0
Suggests
- ext-intl: Slug::clean() drops accents (é → e) only with intl's Normalizer
Provides
None
Conflicts
- preflow/i18n: <0.37
Replaces
None
- dev-main
- v0.77.1
- v0.77.0
- v0.76.0
- v0.75.0
- v0.74.0
- v0.73.0
- v0.72.1
- v0.72.0
- v0.71.1
- v0.71.0
- v0.70.0
- v0.69.2
- v0.69.1
- v0.69.0
- v0.68.1
- v0.68.0
- v0.67.0
- v0.66.2
- v0.66.1
- v0.66.0
- v0.65.0
- v0.64.0
- v0.63.2
- v0.63.1
- v0.63.0
- v0.62.0
- v0.61.0
- v0.60.1
- v0.60.0
- v0.59.0
- v0.58.1
- v0.58.0
- v0.57.0
- v0.56.1
- v0.56.0
- v0.55.0
- v0.54.1
- v0.54.0
- v0.53.2
- v0.53.1
- v0.53.0
- v0.52.0
- v0.51.0
- v0.50.0
- v0.49.1
- v0.49.0
- v0.48.5
- v0.48.4
- v0.48.3
- v0.48.2
- v0.48.1
- v0.48.0
- v0.47.1
- v0.47.0
- v0.46.1
- v0.46.0
- v0.45.0
- v0.44.0
- v0.43.0
- v0.42.1
- v0.42.0
- v0.41.2
- v0.41.1
- v0.41.0
- v0.40.0
- v0.39.0
- v0.38.0
- v0.37.0
- v0.36.0
- v0.35.0
- v0.34.1
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.1
- v0.27.0
- v0.26.0
- v0.25.1
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.1
- v0.18.0
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.0
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.0
This package is auto-updated.
Last update: 2026-11-15 09:43:14 UTC
README
Rules for validating arrays and records. A rule is written as a string alias with parameters
(min:3, between:2,4) or as a ValidationRule instance.
Built-in rules
required, nullable, email, url, numeric, integer, min:n, max:n, between:min,max,
step:n, in:a,b, regex:/pattern/, confirmed, slug, slug:path.
step:n(since 0.46): the value must be a whole multiple ofncounted from 0 (step:0.5accepts2.5, refuses2.3). The check uses the decimal digits of the value and the step, not floats, so0.3is a multiple of0.1and large values stay exact; without bcmath a value too long for an integer is refused. Empty and non-numeric values pass;requiredandnumericjudge those. A step of 0 or below throws anInvalidArgumentException. The message isvalidation.stepwith:step.slug(since 0.52): a part of a web address, lowercasea-zand digits with single hyphens between them (ueber-uns). Umlauts, capitals, spaces, underscores and leading, trailing or double hyphens are refused.slug:pathalso allows single slashes between parts (docs/ueber-uns). Empty values pass. The messages arevalidation.slug.segmentandvalidation.slug.path.Slug::clean($text, path: false)makes text into a valid value (Über uns→ueber-uns,é→e; withpath: truesingle slashes stay); text with no a-z form gives''. Accents are dropped withext-intl'sNormalizer; without it only the letters ä, ö, ü, ß, æ, œ, ø, đ, ł and þ are converted.
Rules for a filled value only
new WhenFilled(...$rules) (since 0.46) runs the wrapped ValidationRule instances only when the value
is filled: null and '' pass, anything else answers with the first failing rule. Unlike nullable
it does not end the chain, so a required next to it still refuses an empty value:
use Preflow\Validation\Rules\{Numeric, Step, WhenFilled}; $rules = ['price' => [new WhenFilled(new Numeric(), new Step(0.5))]]; // empty is fine $rules = ['price' => ['required', new WhenFilled(new Numeric(), new Step(0.5))]]; // empty: "required"
numeric alone keeps refusing ''.
WhenFilled is used as an object only: it has no string alias, and a rule string naming its class would
build it without rules, so it would check nothing.
In an app
When preflow/validation is installed, the application binds RuleFactory and ValidatorFactory
in the container, and registers the rules in app/Rules/ (classes App\Rules\* with
#[RuleAlias('name')]). Since 0.66 this needs no database: it works without config/data.php
too, for forms that are not models. With config/data.php, models validate on save through the
same factory.
$result = $container->get(ValidatorFactory::class)->make(['to' => ['required', 'not_below:from']], $input)->validate();
A package registers its own rule names with RuleFactory::register('name', RuleClass::class) in
its provider.