PHPackages                             rougin/valla - 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. rougin/valla

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

rougin/valla
============

A simple validation package in PHP.

0325PHPCI passing

Since Jan 10Pushed 4mo agoCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Valla
=====

[](#valla)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ced1f697b61a526598f3750178361a8fe96e935ae242ce2478878a2972f94a97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f726f7567696e2f76616c6c612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/valla)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/rougin/valla/blob/master/LICENSE.md)[![Build Status](https://camo.githubusercontent.com/058a7927f62b3f5c92e5bdaff4666471104f0a4bbe0bf1885e97d205cc678ed4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f726f7567696e2f76616c6c612f6275696c642e796d6c3f7374796c653d666c61742d737175617265)](https://github.com/rougin/valla/actions)[![Coverage Status](https://camo.githubusercontent.com/cceb2dfbd4ba9efa6f775a7f15ded7c8d4f421359c7552a9bb2dc2caff05ebe6/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f726f7567696e2f76616c6c613f7374796c653d666c61742d737175617265)](https://app.codecov.io/gh/rougin/valla)[![Total Downloads](https://camo.githubusercontent.com/07176be841f177c05a9fab0312a199c372455072b2bf2c6eb39c774905da76d9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f7567696e2f76616c6c612e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rougin/valla)

A simple validation package based on [Valitron](https://github.com/vlucas/valitron).

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    protected $labels = array(
        'name' => 'Name',
        'email' => 'Email',
    );

    protected $rules = array(
        'name' => 'required',
        'email' => 'required|email',
    );
}

```

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

[](#installation)

Install the package using [Composer](https://getcomposer.org/):

```
$ composer require rougin/valla

```

Basic usage
-----------

[](#basic-usage)

The core of `Valla` is the `Check` class which is used to create a set of validation rules:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    /**
     * @var array
     */
    protected $labels =
    [
        'age' => 'Age',
        'email' => 'Email',
        'name' => 'Name',
    ];

    /**
     * @var array
     */
    protected $rules =
    [
        'age' => 'required|numeric',
        'email' => 'required|email',
        'name' => 'required',
    ];
}

```

The `$labels` property defines user-friendly names for the fields, which will be used in error messages:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    /**
     * @var array
     */
    protected $labels =
    [
        'age' => 'Age',
        'email' => 'Email',
        'name' => 'Name',
    ];

    // ...
}

```

While the `$rules` property specifies the validation rules for each field:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    // ...

    /**
     * @var array
     */
    protected $rules =
    [
        'age' => 'required|numeric',
        'email' => 'required|email',
        'name' => 'required',
    ];
}

```

Note

A list of available rules can be found in the [Valitron documentation](https://github.com/vlucas/valitron#validation-rules).

Once the `Check` class is created, it can be used to validate an array of data, such as data from a HTTP request:

```
$check = new UserCheck;

$data = /* e.g., data from a request */;

if (! $check->valid($data))
{
    // Get all available errors
    $errors = $check->errors();

    // Or get only the first error
    echo $check->firstError();

    return;
}

// Data has passed validation

```

Labels, rules
-------------

[](#labels-rules)

For more complex scenarios, the `labels` and `rules` methods can be overridden to define them dynamically:

```
use Rougin\Valla\Check;

class UserCheck extends Check
{
    /**
     * Returns the specified labels.
     *
     * @return array
     */
    public function labels()
    {
        $this->labels['is_company'] = 'Is a Company?';

        return $this->labels;
    }

    /**
     * Returns the specified rules based on the data.
     *
     * @param array $data
     *
     * @return array
     */
    public function rules($data)
    {
        if (array_key_exists('is_company', $data))
        {
            $this->rules['company_name'] = 'required';
        }

        return $this->rules;
    }
}

```

Using PSR-7 requests
--------------------

[](#using-psr-7-requests)

If using `ServerRequestInterface` from [PSR-7](https://www.php-fig.org/psr/psr-7/), the `Request` class provides a convenient way to validate request data:

```
use Rougin\Valla\Request;

class UserCheck extends Request
{
    /**
     * @var array
     */
    protected $aliases =
    [
        'username' => 'name',
        'email_add' => 'email',
        'new_age' => 'age',
    ];

    // ...
}

```

The `Request` class provides two methods for validation: `isParamsValid` for validating query parameters and `isParsedValid` for validating the parsed body:

```
$check = new UserCheck;

// Should return the ServerRequestInterface ---
$request = Http::getServerRequest();
// --------------------------------------------

// Checks against data from "getQueryParams" ---
if ($check->isParamsValid($request))
{
    // Query parameters are valid
}
// ---------------------------------------------

// Checks against data from "getParsedBody" ---
if ($check->isParsedValid($request))
{
    // Parsed body is valid
}
// --------------------------------------------

```

When an alias is specified, it will be used to look for the field in the `ServerRequestInterface` data. For example, if the request data contains a `username` field, it will be validated against the rules defined for the `name` field.

Overriding the `valid` method
-----------------------------

[](#overriding-the-valid-method)

When extending the `Request` class and overriding the `valid` method, the `setAlias` method must be called to apply the defined aliases:

```
use Rougin\Valla\Request;

class UserCheck extends Request
{
    // ...

    public function valid($data)
    {
        // Always include this if aliases are defined ---
        $data = $this->setAlias($data);
        // ----------------------------------------------

        $valid = parent::valid($data);

        if (! $valid)
        {
            return count($this->errors) === 0;
        }

        // Add extra custom validation conditions here

        return count($this->errors) === 0;
    }
}

```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](https://github.com/rougin/valla/blob/master/CHANGELOG.md) for more recent changes.

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

[](#contributing)

See [CONTRIBUTING](https://github.com/rougin/valla/blob/master/CONTRIBUTING.md) on how to contribute to the project.

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/rougin/valla/blob/master/LICENSE.md) for more information.

###  Health Score

21

—

LowBetter than 18% of packages

Maintenance52

Moderate activity, may be stable

Popularity12

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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/c7721589a958a1fbcef1b527c794d820d75b82988f14b2ed86a1c6904d76a59e?d=identicon)[rougin](/maintainers/rougin)

---

Top Contributors

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

---

Tags

php-validationphp-validator

### Embed Badge

![Health badge](/badges/rougin-valla/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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