PHPackages                             terminusstudio/phpvalidator - 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. terminusstudio/phpvalidator

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

terminusstudio/phpvalidator
===========================

A PHP validator using respect validator. Built for Slim.

1.1.0(5y ago)036MITPHPPHP ^7.3 || ^8.0

Since Jan 2Pushed 5y ago1 watchersCompare

[ Source](https://github.com/TerminusStudio/PHPValidator)[ Packagist](https://packagist.org/packages/terminusstudio/phpvalidator)[ Docs](https://github.com/TerminusStudio/PHPValidator)[ RSS](/packages/terminusstudio-phpvalidator/feed)WikiDiscussions main Synced 6d ago

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

Slim PHP Respect Validation
===========================

[](#slim-php-respect-validation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cf71ffa1955cf5922a95cbd39e38dedab7fbc96babf36662679f76df5e078d5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f5465726d696e757353747564696f2f50485056616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/TerminusStudio/PHPValidator)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://github.com/TerminusStudio/PHPValidator/workflows/CI/badge.svg)](https://github.com/TerminusStudio/PHPValidator/actions?query=workflow%3ACI)[![Scrutinizer](https://camo.githubusercontent.com/4a4f7f86afca1a9fbe32c89eac107e7822505f4bec85c6e863511c66f0abfbf4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f5465726d696e757353747564696f2f50485056616c696461746f72)](https://scrutinizer-ci.com/g/TerminusStudio/PHPValidator/?branch=main)[![Total Downloads](https://camo.githubusercontent.com/36ecb5afd7573fa454dd8fdf82d8ad2ff3d668de6d6afaa63945612bb57d0005/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f5465726d696e757353747564696f2f50485056616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/TerminusStudio/PHPValidator)

A SlimPHP validator using respect validation package.

Install
-------

[](#install)

Via Composer

```
$ composer require terminusstudio/phpvalidator
```

Usage
-----

[](#usage)

### Initializing

[](#initializing)

**Configuration**

```
$config = [
            'useSession' => false
          ];
```

- `useSession` - If set to true, validation results are saved in a session variable that can be accessed in the next request (using the ValidatorMiddleware). Defaults to false.

**Using a container**

```
Container::set('validator', function() {
    return new \TS\PHPValidator\Validator($config);
});
```

**Without container**

```
$validator = new \TS\PHPValidator\Validator($config);
```

### Example Usage

[](#example-usage)

```
public function login($request, $response) {
    if ($request->getMethod() == 'POST')
    {
        $v = Container::get('validator')->validate($request, [
            'email' => v::noWhitespace()->notEmpty()->email(),
            'password' => v::notEmpty()->length(8)->alnum('_'),

        ]);;

        if($v->isValid())
        {
            //Do Processing
        }
     }
    return View::render($response, 'login.twig');
}
```

#### Middleware

[](#middleware)

The ValidatorMiddleware can be added to slim if you set the useSession to true in $config.

```
  public function postLogin($request, $response) {
        $v = Container::get('validator')->validate($request, [
            'email' => v::noWhitespace()->notEmpty()->email(),
            'password' => v::notEmpty()->length(8)->alnum('_'),

        ]);;

        if($v->isValid())
        {
            //Do Processing
        }

        return $response->withHeader('Location',  Router::getRouteParser()->urlFor('login.get'))->withStatus(302);;
    }
```

If there were any errors, the next request will have access to the errors and values. To enable the middleware just add `ValidatorMiddleware` class to the Slim app and pass the validator instance.

```
$app->add(new \TS\PHPValidator\ValidatorMiddleware(Container::get('validator')));
```

#### Twig Extension

[](#twig-extension)

This plugin also supports Twig functions. To enable just add `ValidatorTwig` when initializing twig. This requires `slim/twig-view` package.

```
Container::set('view', function() {
    $view = Twig::create(....);

    // Add the validator extension and pass the validator instance to it
    $view->addExtension(
        new \TS\PHPValidator\ValidatorTwig(Container::get('validator'))
    );

    return $view;
});
```

There are currently 5 functions supported by the extension,

- `has_errors()` - Returns true if there are any errors
- `has_error($key)` - Returns true if `$key` is invalid
- `get_errors()` - Returns an array containing all errors
- `get_error($key, $toString = true)` - Returns an array containing all errors for a specific `$key`. If `$toString` is set to true, then it returns a string.
- `get_value($key, $default = null)` - Returns the value for a specific `$key`.

*`$key` is the field name set in the request.*

```
{% if has_error('email') %}
    {{  get_error('email') }}
{% endif %}

```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

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.

###  Release Activity

Cadence

Every ~121 days

Total

2

Last Release

1840d ago

PHP version history (2 changes)1.0.0PHP ^7.4 || ^8.0

1.1.0PHP ^7.3 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![Sugavanas](https://avatars.githubusercontent.com/u/8426015?v=4)](https://github.com/Sugavanas "Sugavanas (21 commits)")

---

Tags

phpphp-libraryslimslim-frameworktwig-extensionvalidationvalidatorvalidatorvalidationrespectslimtwig-extensionTerminusStudio

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/terminusstudio-phpvalidator/health.svg)

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

###  Alternatives

[respect/validation

The most awesome validation engine ever created for PHP

5.9k37.4M383](/packages/respect-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)[opis/json-schema

Json Schema Validator for PHP

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

A slim middleware for validation based on Respect/Validation

171223.7k3](/packages/davidepastore-slim-validation)[workerman/validation

The most awesome validation engine ever created for PHP. Respect/Validation 汉化版本

2334.1k9](/packages/workerman-validation)[resultsystems/validation

Inspired 'KennedyTedesco Validation' - The power of 'Respect Validation' on Laravel.

2832.4k4](/packages/resultsystems-validation)

PHPackages © 2026

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