PHPackages                             cucher/validata - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. cucher/validata

ActiveLibrary

cucher/validata
===============

Validate custom data classes (framework agnostic)

05PHP

Since May 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/ckressibucher/php-validata)[ Packagist](https://packagist.org/packages/cucher/validata)[ RSS](/packages/cucher-validata/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Data validation
===============

[](#data-validation)

A library to validate structured data against a schema.

Status
------

[](#status)

[![Build Status](https://camo.githubusercontent.com/cb04b27b6911b348d8874cd5d443101cdc1c62b96319588e275ac7ce0131e7fe/68747470733a2f2f7472617669732d63692e6f72672f636b72657373696275636865722f7068702d76616c69646174612e737667)](https://travis-ci.org/ckressibucher/php-validata)[![Coverage Status](https://camo.githubusercontent.com/4d2a34d6455d1a280acd12dbdabe31f191b346c7dcfa69b57f6340c6258ceafc/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f636b72657373696275636865722f7068702d76616c69646174612f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/ckressibucher/php-validata?branch=master)

This library is currently actively developed, and changed to its API should be expected. If you want to use it in production, please check the status again in a few weeks...

Why and how
-----------

[](#why-and-how)

Most common web applications handle *structural* input data. Examples are:

- Data sent by HTML forms
- JSON or XML Data for AJAX Requests
- JSON or XML Data sent to server APIs

In all cases, the data has to be validated. Often enough, this validation is mixed with other tasks, maybe even with business logic. The goal of this library is to separate the validation step from the business logic.

How does it work? This library provides:

- Primitives to define a validation schema, and to validate input data against this schema.
- Classes representing results and describing errors including their exact location.

The intended usage is:

1. For each controller action that handles non trivial input data, a schema is defined. This schema defines the structure of the whole data, as well as additional characteristics of each single value.
2. The input data is validated against this schema. The result contains two parts:
    - the part of the input data that is valid
    - a list of errors, each containing detailed information about the location and the exact type of error. This information can be used to report errors to the client.
3. The controller action decides how it handles the result. Mostly, if there are any errors, the action will send a 400 HTTP response including information about the errors. If there are no errors, it may invoke some business modules to further process the data.

Dependencies
------------

[](#dependencies)

For "low level validations", i.e. to validate single scalar values, the [Respect Validation Library](https://github.com/Respect/Validation) is used. There are no dependencies to any full stack frameworks. The library is desiged to be easily integrated into any application structure.

Usage
-----

[](#usage)

```
use Ckr\Validata\Schema;
use Ckr\Validata\Validator;
use Respect\Validation\Rules;

function action()
{
    $schema = getValidationSchema();
    $result = Validator::run($schema, $_POST);
    if ($result->hasErrors()) {
        handleErrors($result->getErrors());
    } else {
        handleRequest($result->getValidData());
    }
}

/**
 * Builds the validation schema for `action`
 */
function getValidationSchema()
{
    $mainSchema = new Schema\Map();
    $emailSchema = new Schema\Scalar(new Rules\Email());
    $usernameSchema = new Schema\Scalar(new Rules\Alnum());
    $mainSchema->property('email', $emailSchema);
    $mainSchema->property('username', $usernameSchema);

    return $mainSchema;
}

function handleErrors(array $errors)
{
    // TODO handle errors...
}

function handleRequest(array $validData)
{
    // TODO implement the actual business logic
}
```

While this looks like lots of code, much of it is always the same and can be abstracted. How this is done, varies with the framework or application structure.

Especially the error handling can probably be reused for all actions of the same API or application, as the errors have detailed information, that can easily be transformed in a JSON Response (or any other structured data format).

The creation of the schema is a bit tedious. I will probably provide builders or similar helpers in near future to make composing various subschemas easier.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/81e52f2fb24def14cbf90069f298696540f5268e48efff17ab0d53df1ac41137?d=identicon)[ckressibucher](/maintainers/ckressibucher)

---

Top Contributors

[![ckressibucher](https://avatars.githubusercontent.com/u/3111098?v=4)](https://github.com/ckressibucher "ckressibucher (1 commits)")

### Embed Badge

![Health badge](/badges/cucher-validata/health.svg)

```
[![Health](https://phpackages.com/badges/cucher-validata/health.svg)](https://phpackages.com/packages/cucher-validata)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
