Download the PHP package iviphp/validation without Composer

On this page you can find all versions of the php package iviphp/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

Ivi Validation

Validation rules and data validation for the IviPHP ecosystem.

Overview

iviphp/validation provides a small object-based validation system for IviPHP packages and applications.

It supports:

The package is framework-independent and does not depend on HTTP, routing, controllers or global application state.

Installation

Requirements

Basic validation

Check the result:

Creating a validator

A validator can be created and reused.

Nested fields

Dot notation can validate nested input values.

Validated values preserve their nested structure.

Result:

Required fields

The Required rule rejects:

The following values are accepted:

Nullable fields

When the value is null, Nullable causes the remaining rules to be skipped.

Empty strings are not treated as null.

This value still fails the Email rule.

Required takes precedence over Nullable.

A null value still fails because the field is required.

String validation

StringType accepts only real PHP strings.

It does not convert integers, booleans or other values automatically.

Integer validation

The string '12' does not pass IntegerType.

Use Numeric when numeric strings should be accepted.

Numeric validation

Numeric accepts:

It rejects:

Email validation

Email validation uses PHP's FILTER_VALIDATE_EMAIL.

Leading or trailing whitespace is rejected instead of silently removed.

Minimum length

MinLength supports strings and arrays.

Strings are measured with mb_strlen() when the Mbstring extension is available. Otherwise, byte length is used.

Maximum length

Arrays can also be limited:

Allowed values

Strict comparison is enabled by default.

The string '1' does not match the integer 1.

Non-strict comparison can be enabled explicitly:

Custom validation messages

Most built-in rules accept an optional custom message.

Supported placeholders depend on the rule.

Common placeholders include:

Validation results

A validation operation returns a ValidationResult.

Return all errors:

Example:

Check one field:

Return all messages for one field:

Return the first message for one field:

Return the first message from the complete result:

Return every message as a flat list:

Return the total number of errors:

Validated data

Only fields declared in the validation rules are returned as validated data.

Result:

The undeclared admin value is excluded.

Retrieve one validated value:

Nested dot notation is supported:

Check whether validated data contains a key:

Fields that fail validation are excluded from validated data.

Optional fields

A field that is absent and does not use Required is skipped.

This validation passes because nickname is optional.

When the optional field exists, its rules are applied.

Stopping after the first error

By default, the validator collects every failure for each field.

Enable early termination per field:

A reusable validator can also be changed immutably.

Validation exceptions

A failed result can be wrapped in a ValidationException.

Catch the exception:

Available exception methods:

A ValidationException cannot be created from a successful result.

Custom rules

Custom validation rules implement RuleInterface.

Use the custom rule normally:

The complete input array is provided to each rule.

This enables cross-field validation.

Complete example

Available classes

RuleInterface

Validator

ValidationResult

ValidationException

Built-in rules

Required

Requires a non-empty value.

Nullable

Allows null and skips remaining rules.

StringType

Requires a PHP string.

IntegerType

Requires a PHP integer.

Numeric

Requires an integer, finite float or numeric string.

Email

Requires a valid email address.

MinLength

Requires a minimum string character count or array element count.

MaxLength

Requires a maximum string character count or array element count.

In

Requires a value to exist in an allowed list.

Design principles

This package validates values but does not transform them automatically.

Data normalization, sanitization and type conversion should happen explicitly before or after validation depending on application requirements.

Package boundaries

This package is responsible for:

It is not responsible for:

Database-aware and application-aware rules should be implemented in higher-level packages or application code.

Ecosystem

This package is part of the IviPHP ecosystem:

Contributing

Contributions should preserve the focused scope of this package.

New rules should:

Security

Validation does not replace security controls such as:

Input should be validated as close as possible to the application boundary.

Please report security issues privately to the Softadastra maintainers instead of opening a public issue.

License

This project is licensed under the MIT License.

Maintainer

Created and maintained by Softadastra.


All versions of validation with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
iviphp/support Version ^0.1
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 iviphp/validation contains the following files

Loading the files please wait ...