PHPackages                             zfegg/content-validation - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. zfegg/content-validation

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

zfegg/content-validation
========================

Content validation for PSR-15 middleware

6.0.0(1y ago)01.4k1MITPHPPHP &gt;=7.4CI failing

Since Nov 14Pushed 1y ago2 watchersCompare

[ Source](https://github.com/zfegg/content-validation)[ Packagist](https://packagist.org/packages/zfegg/content-validation)[ RSS](/packages/zfegg-content-validation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (15)Versions (22)Used By (1)

PSR-15 Content Validation
=========================

[](#psr-15-content-validation)

[简体中文](README-zh.md)

[![GitHub Actions: Run tests](https://github.com/zfegg/content-validation/workflows/qa/badge.svg)](https://github.com/zfegg/content-validation/actions?query=workflow%3A%22qa%22)[![Coverage Status](https://camo.githubusercontent.com/d399ab60533cd2815da36befdd9a9b880feca0d928206d0aea65dc366500b3fe/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7a666567672f636f6e74656e742d76616c69646174696f6e2f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/zfegg/content-validation?branch=master)[![Latest Stable Version](https://camo.githubusercontent.com/94f6d1bc722f5c3b8a43e97b8617c40565e9f99e014d1df3a03b32d2cb6ddff0/68747470733a2f2f706f7365722e707567782e6f72672f7a666567672f636f6e74656e742d76616c69646174696f6e2f762f737461626c652e706e67)](https://packagist.org/packages/zfegg/content-validation)

Content validation for PSR-15 middleware. Based on [`opis/json-schema`](https://packagist.org/packages/opis/json-schema).

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

[](#installation)

Install via composer.

```
composer require zfegg/content-validation
```

Usage
-----

[](#usage)

### `Opis\JsonSchema\Validator` factory config.

[](#opisjsonschemavalidator-factory-config)

```
// config.php
return [
    Opis\JsonSchema\Validator::class => [
        'resolvers' => [
            'protocolDir' => [
                // foo-schema://host/foo.create.json => schema/dir/foo.create.json
                ['foo-schema', 'host',  'schema/dir'],
            ],
            'protocol' => [
            ],
            'prefix' => [
               ['prefix1', 'path/to/dir'],
               ['prefix2', 'path/to/dir'],
            ],
            'file' => [
               ['SchemaFoo', 'path/to/file'],
               ['SchemaBar', 'path/to/file2'],
            ],
            'raw' => [
               ['{"type":"object", ...}', 'schema id 1'],
               ['{"type":"object", ...}', 'schema id 2'],
            ]
        ],
        'filters' => [
            'foo-filter' => ['filter' => 'FilterFilterName', 'types' => ['integer']],
        ],
        'filtersNS' => [
            'foo-ns' => 'FilterResolverName',
        ],
    ]
]
```

### Mezzio

[](#mezzio)

Add `ConfigProvider` in 'config.php'.

```
$aggregator = new ConfigAggregator(
  [
    // ...
    \Zfegg\ContentValidation\ConfigProvider::class,
  ]
);

return $aggregator->getMergedConfig();
```

```
$app->post(
  '/api/users',
   [
   \Zfegg\ContentValidation\ContentValidationMiddleware::class,
    function (\Psr\Http\Message\ServerRequestInterface $request) {
        $data = $request->getParsedBody(); // Get valid data.
    }
], 'api.users.create')
->setOptions(['schema' => 'path-to-json-schema.json'])
//->setOptions([
//   // or set json-schema object.
//  'schema' => (object) [
//        'type' => 'object',
//        'properties' => (object) [
//             'age' => (object) [
//                 'type' => 'integer'
//              ]
//        ],
//        'required' => ['age']
//   ]
// ])
;
```

Invalid request will response status 422.

```
curl "http://host/api/users" -d 'username=foo'

HTTP/1.1 422

{
  "status": 422,
  "detail": "Failed Validation",
  "validation_messages": {
    "age": [
      "The required properties (age) are missing"
    ]
  }
}
```

### Slim

[](#slim)

```
$app->post(
  '/api/users',
  function (\Psr\Http\Message\ServerRequestInterface $request) {
        $data = $request->getParsedBody(); // Get valid data.
  }
)
->add(\Zfegg\ContentValidation\ContentValidationMiddleware::class)
->setArgument('schema', 'path-to-json-schema.json')
;
```

Validators
----------

[](#validators)

- [`DbalRecordExistsFilter`](src/Opis/Filter/DbalRecordExistsFilter.php): Use `doctrine/dbal` to check record exists. The json-schema `$filters` config: ```
    {
        "$func": "dbal-exists",
        "$vars": {
          "db": "db",          // Get DBAL object by container.
          "sql": "select ...", // Set custom SQL
          "table": "foo",      // Table name
          "field": "key",      // Field name
          "exists": true       // Check record exists or not exists. Default: false
        }
    }
    ```
- [`DoctrineRecordExistsFilter`](src/Opis/Filter/DoctrineRecordExistsFilter.php): Use `doctrine/orm` to check record exists. The json-schema `$filters` config: ```
    {
        "$func": "orm-exists",
        "$vars": {
          "db": "orm.default",   // Get ORM object by container.
          "dql": "select ...",   // Set custom DQL
          "entity": "Foo",       // Entity name
          "field": "key",        // Field name
          "exists": true         // Check record exists or not exists. Default: false
        }
    }
    ```
- [`RecordExistsFilter`](src/Opis/Filter/RecordExistsFilter.php): Use `PDO` to check record exists. The json-schema `$filters` config: ```
    {
        "$func": "db-exists",
        "$vars": {
          "db": "db",          // Get DBAL object by container.
          "sql": "select ...", // Set custom SQL
          "table": "foo",      // Table name
          "field": "key",      // Field name
          "exists": true       // Check record exists or not exists. Default: false
        }
    }
    ```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity72

Established project with proven stability

 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.

###  Release Activity

Cadence

Every ~137 days

Recently: every ~273 days

Total

19

Last Release

631d ago

Major Versions

1.1.0 → 2.0.02018-03-27

2.0.1 → 3.0.02020-01-09

3.0.1 → 4.0.02021-01-31

4.0.1 → 5.0.02021-08-04

5.5.0 → 6.0.02024-08-22

PHP version history (3 changes)2.0.0PHP ^7.1

4.0.0PHP &gt;=7.3

5.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2050694?v=4)[Moln](/maintainers/Moln)[@Moln](https://github.com/Moln)

---

Top Contributors

[![Moln](https://avatars.githubusercontent.com/u/2050694?v=4)](https://github.com/Moln "Moln (89 commits)")

---

Tags

json-schemaphpvalidationmiddlewarevalidationjson-schemaslimmezziopsr15content-validation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/zfegg-content-validation/health.svg)

```
[![Health](https://phpackages.com/badges/zfegg-content-validation/health.svg)](https://phpackages.com/packages/zfegg-content-validation)
```

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

64236.9M186](/packages/opis-json-schema)[selective/validation

Validation error collector and transformer

35106.8k1](/packages/selective-validation)[awurth/slim-validation

A wrapper around the respect/validation PHP validation library for easier error handling and display

65378.4k9](/packages/awurth-slim-validation)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1036.7k3](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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