Download the PHP package meritum/validation without Composer

On this page you can find all versions of the php package meritum/validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package validation

meritum/validation

Validation library for the Meritum ecosystem. Provides a rule-agnostic engine, a set of 31 default rules, and kernel integration via ValidationModule.

Requirements

Installation

Usage

Inject Validator and call validate() with a schema and input array. The schema maps attribute names to a list of rules. Rules are plain strings; rules with parameters use the attribute name as the key and an array of parameters as the value.

Optionality and nullability

Rules Missing null Present
['string'] passes fails validated
['required', 'string'] fails (stops) fails (stops) validated
['nullable', 'string'] passes passes validated
['nullable', 'required', 'string'] fails (stops) passes validated

Dot notation and wildcards

Nested attributes use dot notation. Wildcards validate each element of an array. Both can be combined and nested arbitrarily.

Errors for wildcard attributes are keyed by the concrete path — items.1.name, items.0.variants.2.sku, etc. If the parent is absent or not an array, the wildcard path passes silently — combine with a separate rule on the parent attribute to enforce its presence.

Module registration

Register ValidationModule with the kernel to wire up the engine and all default rules.

The module binds Validator::class to ValidationEngine via ValidationEngineFactory, and tags all 31 default rules with validation.rules. The factory resolves tagged rules at boot time and spreads them into the engine.

Adding custom rules

Implement RuleInterface and register the class with the kernel tagged as validation.rules. The rule's name() return value is the string used in schemas.

Overriding a default rule

Register a new class that returns the same name() as the rule you want to replace. The last registration wins.

Stoppable rules

Implement StoppableRuleInterface to halt validation of remaining rules for an attribute when a condition is met. shouldPropagationStop() is called after validate() and receives the same value and params.

Field-referencing rules

Implement FieldReferencingRuleInterface for rules that compare a value against another field in the input. resolveParams() receives the comparison field name (from the schema) and the full input, and returns the params passed to validate() and message().

Default rules

Presence and flow

Rule Schema Description
required 'required' Must be present, non-null, and non-empty string; stops propagation on failure
nullable 'nullable' Null passes and remaining rules are skipped

Type

Rule Schema Description
string 'string' Must be a string
integer 'integer' Must be an integer
float 'float' Must be a float (integers do not pass — use numeric for "can be cast to number")
boolean 'boolean' Must be a boolean
array 'array' Must be an array
numeric 'numeric' Must be numeric — accepts integers, floats, and numeric strings

String

Rule Schema Description
alpha 'alpha' Letters only (a–z, A–Z)
alphaNum 'alphaNum' Letters and digits only
email 'email' Valid email address
url 'url' Valid URL
uuid 'uuid' Valid UUID (any version)
ip 'ip' Valid IPv4 or IPv6 address
ipv4 'ipv4' Valid IPv4 address
ipv6 'ipv6' Valid IPv6 address
regex 'regex' => ['/pattern/'] Matches the given regular expression
lengthMin 'lengthMin' => [4] Minimum string length (multibyte-safe)
lengthMax 'lengthMax' => [255] Maximum string length (multibyte-safe)
lengthBetween 'lengthBetween' => [4, 255] Length between min and max inclusive

Numeric

Rule Schema Description
min 'min' => [0] Value must be ≥ min
max 'max' => [100] Value must be ≤ max
between 'between' => [1, 100] Value must be between min and max inclusive

Comparison

Rule Schema Description
equals 'equals' => ['value'] Strict equality against a literal value
notEquals 'notEquals' => ['value'] Strict inequality against a literal value
in 'in' => ['a', 'b', 'c'] Value must be in the given list (strict)
notIn 'notIn' => ['a', 'b'] Value must not be in the given list (strict)

Field comparison

Rule Schema Description
sameAs 'sameAs' => 'other_field' Must strictly equal another field's value
differentFrom 'differentFrom' => 'other_field' Must strictly differ from another field's value

Date

Rule Schema Description
date 'date' Valid calendar date string or DateTimeInterface; rejects relative strings like "next Tuesday"
dateFormat 'dateFormat' => ['Y-m-d'] Date string matching the given date() format exactly

License

MIT — see LICENSE.


All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
georgeff/kernel Version ^2.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package meritum/validation contains the following files

Loading the files please wait ...