PHPackages                             webdevcave/schema-validator - 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. webdevcave/schema-validator

ActiveLibrary

webdevcave/schema-validator
===========================

Schema validation, 'Zod' like validation

v0.1-alpha(1y ago)00MITPHPPHP &gt;=8.1CI passing

Since Jan 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/WebdevCave/schema-validator-php)[ Packagist](https://packagist.org/packages/webdevcave/schema-validator)[ RSS](/packages/webdevcave-schema-validator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Schema Validator
================

[](#schema-validator)

[![codecov](https://camo.githubusercontent.com/08978e5b14aed14b03c68154ffe038ce2581dcfe19896e50afb506056135fec2/68747470733a2f2f636f6465636f762e696f2f67682f576562646576436176652f736368656d612d76616c696461746f722d7068702f67726170682f62616467652e7376673f746f6b656e3d6c433273636a7637436f)](https://codecov.io/gh/WebdevCave/schema-validator-php)[![StyleCI](https://camo.githubusercontent.com/71be565923bb1b8485599458f4a40612c98a9f9a49d95570a0f82545eb38902c/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3931313736333630302f736869656c643f6272616e63683d6d61696e)](https://camo.githubusercontent.com/71be565923bb1b8485599458f4a40612c98a9f9a49d95570a0f82545eb38902c/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3931313736333630302f736869656c643f6272616e63683d6d61696e)

A simple schema validation library for PHP. This package allows you to define rules for your data and validate it easily.

Table of Contents
-----------------

[](#table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Basic Usage](#basic-usage)
    - [Dataset Schema Example](#dataset-validation-example)
- [Contributing](#contributing)
- [License](#license)

Installation
------------

[](#installation)

To install the Schema Validator PHP library, you can use Composer. Run the following command:

```
composer require webdevcave/schema-validator-php
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

```
use Webdevcave\SchemaValidator\Validator;

$validator = Validator::string()
    ->min(3)
    ->max(50);

// Validate the data
$isValid = $validator->validate('Carlos');

if ($isValid) {
    echo "Data is valid!";
} else {
    echo "Data is invalid!";
}
```

### Dataset Validation Example

[](#dataset-validation-example)

The library also allows you to define more complex validation rules for nested structures or arrays. For example:

```
use Webdevcave\SchemaValidator\Validator;

$validator = Validator::array([
    'name' => Validator::string()
        ->min(3)
        ->max(50),
    'email' => Validator::string()
        ->pattern('/^\w+@(\w+|\.)+$/'),
    'address' => Validator::array([
        'street' => Validator::string()->max(200),
        'city' => Validator::string()->max(50),
        'postal_code' => Validator::string()
            ->min(1)
            ->max(15),
    ])
]);

// Data to be validated
$data = [
    'name' => 'Alice Johnson',
    'email' => 'alice.johnson@example.com',
    'address' => [
        'street' => '123 Maple St',
        'city' => 'Somewhere',
        'postal_code' => '12345'
    ]
];

// Validate the data
$isValid = $validator->validate($data);

if ($isValid) {
    echo "Data is valid!";
} else {
    echo "Data is invalid!";
}
```

For objects, just use `Validator::object()` in a similar way.

### Validation Error Handling

[](#validation-error-handling)

If the data is invalid, you can get more detailed error information:

```
use Webdevcave\SchemaValidator\Validator;

// Data to be validated
$data = [
    'name' => 'John Doe',
    'age' => 'thirty'
];

// Define the validation schema
$validator = Validator::array([
    'name'  => Validator::string(),
    'age'   => Validator::numeric()
        ->integer('Only integer numbers are allowed')
        ->positive('Age field must be positive')
]);

// Validate the data
if (!$validator->validate($data)) {
    // Get and print the validation errors
    print_r($validator->errorMessages());
}
```

This will output something like:

```
Array
(
    [age] => Array
    (
        [0] => Only integer numbers are allowed,
        [1] => Age field must be positive,
    )
)

```

Contributing
------------

[](#contributing)

We welcome contributions to this project! If you'd like to help improve the Schema Validator PHP library, please follow these steps:

### How to Contribute

[](#how-to-contribute)

1. Fork this repository to your GitHub account.
2. Create a new branch for your feature or fix.
3. Make your changes and test them thoroughly.
4. Submit a pull request with a description of your changes and why they're needed.

### Code Style

[](#code-style)

Please follow the [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standards for PHP when making contributions.

### Issues

[](#issues)

If you encounter any bugs or have suggestions for improvements, please open an issue in the GitHub repository.

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance41

Moderate activity, may be stable

Popularity0

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

 Bus Factor1

Top contributor holds 95.8% 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

490d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5069326?v=4)[Carlos Alberto Bertholdo Carucce](/maintainers/carloscarucce)[@carloscarucce](https://github.com/carloscarucce)

---

Top Contributors

[![carloscarucce](https://avatars.githubusercontent.com/u/5069326?v=4)](https://github.com/carloscarucce "carloscarucce (23 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/webdevcave-schema-validator/health.svg)

```
[![Health](https://phpackages.com/badges/webdevcave-schema-validator/health.svg)](https://phpackages.com/packages/webdevcave-schema-validator)
```

PHPackages © 2026

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