PHPackages                             semhoun/slim-request-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. [Framework](/categories/framework)
4. /
5. semhoun/slim-request-validation

ActiveLibrary[Framework](/categories/framework)

semhoun/slim-request-validation
===============================

A Slim middleware for HTTP request validation based on Respect/Validation

1.5.0(2mo ago)09↓100%GPL-2.0-or-laterPHPPHP ^8.5

Since Apr 10Pushed 2mo agoCompare

[ Source](https://github.com/semhoun/slim-request-validation)[ Packagist](https://packagist.org/packages/semhoun/slim-request-validation)[ RSS](/packages/semhoun-slim-request-validation/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (6)Versions (2)Used By (0)

Slim Framework Request Validation
=================================

[](#slim-framework-request-validation)

A **Request** validation library for the Slim 4 Framework. It uses the [respect/validation](https://github.com/Respect/Validation) library.

This repository is a fork of `https://github.com/benycode/slim-request-validation`.

Table of contents
-----------------

[](#table-of-contents)

- [Install](#install)
- [Compatibility](#compatibility)
- [Usage](#usage)
- [Testing](#testing)

Install
-------

[](#install)

Via Composer

```
$ composer require semhoun/slim-request-validation
```

Requires PHP 8.5+ and Slim 4.

Compatibility
-------------

[](#compatibility)

- PHP: `^8.5`
- Slim Framework: `^4.15`
- `respect/validation`: `^3.1`
- `slim/psr7`: `^1.7 || ^2.0`
- `phpunit/phpunit` for development: `^12.0 || ^13.0`

Usage
-----

[](#usage)

Create a **Rule** class:

```
use BenyCode\Slim\Validation\Rule\RequestValidationRuleInterface;
use Respect\Validation\ValidatorBuilder as v;

final class AnyRuleClass implements RequestValidationRuleInterface
{
    public function rules(): array
    {
        return [
            'name' => v::alpha(),
            'url' => v::url(),
        ];
    }

    public function messages(): array
    {
        return [
            'url' => 'url must be a URL',
        ];
    }
}
```

With `respect/validation` 3.x, validators are built with `Respect\Validation\ValidatorBuilder` instead of the older static `Validator` API.

Add the middleware to a route:

```
use BenyCode\Slim\Validation\RequestValidation;
use BenyCode\Slim\Validation\Middleware\RequestValidationExceptionMiddleware;
use BenyCode\Slim\Validation\Transformer\RequestValidatorTransformFactory;
use BenyCode\Slim\Validation\Encoder\JsonEncoder;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

$app->post('/api/any_end_point', function ($request, $response) {
    return $response;
})
    ->add(new RequestValidationExceptionMiddleware(new RequestValidatorTransformFactory(), new JsonEncoder()))
    ->add(new RequestValidation([
        new AnyRuleClass(),
    ]));

$app->run();
```

Keep your code clean and split rules across classes when needed:

```
use BenyCode\Slim\Validation\RequestValidation;
use BenyCode\Slim\Validation\Middleware\RequestValidationExceptionMiddleware;
use BenyCode\Slim\Validation\Transformer\RequestValidatorTransformFactory;
use BenyCode\Slim\Validation\Encoder\JsonEncoder;
use Slim\Factory\AppFactory;

$app = AppFactory::create();

$app->post('/api/any_end_point', function ($request, $response) {
    return $response;
})
    ->add(new RequestValidationExceptionMiddleware(new RequestValidatorTransformFactory(), new JsonEncoder()))
    ->add(new RequestValidation([
        new AnyRuleClass(),
        new AppendedRuleClass(),
        new AppendedRule2Class(),
        new AppendedRule3Class(),
    ]));

$app->post('/api/any_end_point2', function ($request, $response) {
    return $response;
})
    ->add(new RequestValidationExceptionMiddleware(new RequestValidatorTransformFactory(), new JsonEncoder()))
    ->add(new RequestValidation([
        new AnyRuleClass(),
        new AppendedRule3Class(),
    ]));

$app->run();
```

Testing
-------

[](#testing)

```
composer test
```

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance88

Actively maintained with recent releases

Popularity5

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

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

60d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/efb83f2b876f8b6122c07c99af97df13bf208ba264d77b7b08dc1a1e30365e20?d=identicon)[semhoun](/maintainers/semhoun)

---

Top Contributors

[![benycode](https://avatars.githubusercontent.com/u/39025147?v=4)](https://github.com/benycode "benycode (33 commits)")[![semhoun](https://avatars.githubusercontent.com/u/54236487?v=4)](https://github.com/semhoun "semhoun (1 commits)")

---

Tags

requestmiddlewareframeworkvalidatorvalidationslim

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/semhoun-slim-request-validation/health.svg)

```
[![Health](https://phpackages.com/badges/semhoun-slim-request-validation/health.svg)](https://phpackages.com/packages/semhoun-slim-request-validation)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k86.9M2.2k](/packages/symfony-symfony)[cakephp/cakephp

The CakePHP framework

8.8k19.1M1.7k](/packages/cakephp-cakephp)[davidepastore/slim-validation

A slim middleware for validation based on Respect/Validation

170227.3k3](/packages/davidepastore-slim-validation)[neuron-core/neuron-ai

The PHP Agentic Framework.

1.9k496.1k32](/packages/neuron-core-neuron-ai)[slim/csrf

Slim Framework 4 CSRF protection PSR-15 middleware

3722.1M99](/packages/slim-csrf)[slim/http-cache

Slim Framework HTTP cache middleware and service provider

1163.1M31](/packages/slim-http-cache)

PHPackages © 2026

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