PHPackages                             mrferos/comfort - 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. mrferos/comfort

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

mrferos/comfort
===============

Data validation library

0.2.5(10y ago)21.3k1MITPHP

Since May 15Pushed 9y ago3 watchersCompare

[ Source](https://github.com/mrferos/comfort)[ Packagist](https://packagist.org/packages/mrferos/comfort)[ RSS](/packages/mrferos-comfort/feed)WikiDiscussions master Synced 4w ago

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

Comfort
=======

[](#comfort)

[![Travis-CI](https://camo.githubusercontent.com/53529fe962dd3c376405764febeea35a8106da91b97c1665262eefaeb646aea0/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d726665726f732f636f6d666f72742e737667)](https://camo.githubusercontent.com/53529fe962dd3c376405764febeea35a8106da91b97c1665262eefaeb646aea0/68747470733a2f2f6170692e7472617669732d63692e6f72672f6d726665726f732f636f6d666f72742e737667)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/811759d19341e4ec50a4c3102f67f20113bb50c6da63cabcd22693cad238d8bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d726665726f732f636f6d666f72742f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mrferos/comfort/?branch=master)[![Coverage Status](https://camo.githubusercontent.com/fe3f87283f59e1527ee03ad2460fedfebcfc62ec67f568bafdd731d776aaf501/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d726665726f732f636f6d666f72742f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mrferos/comfort?branch=master)

Easy &amp; Flexible validation for your data.
---------------------------------------------

[](#easy--flexible-validation-for-your-data)

Comfort is an easy to use validation lib styled after [Joi](https://github.com/hapijs/joi), an excellent (and so far, better featured) object validation lib.

Example
-------

[](#example)

```
$json = 'ALABAMA',
    'AK'=>'ALASKA',
    'AS'=>'AMERICAN SAMOA',
    'AZ'=>'ARIZONA',
    'AR'=>'ARKANSAS',
    'CA'=>'CALIFORNIA',
    'CO'=>'COLORADO',
    'CT'=>'CONNECTICUT',
    'DE'=>'DELAWARE',
    'DC'=>'DISTRICT OF COLUMBIA',
    'FM'=>'FEDERATED STATES OF MICRONESIA',
    'FL'=>'FLORIDA',
    /** taken out for brevity */
);

$registrationSchema = cmf()->json()->keys([
    "first_name" => cmf()->string()->required()->alpha()->min(1),
    "last_name"  => cmf()->string()->required()->alpha()->min(1),
    "email" => cmf()->string()->email(),
    "address"    => cmf()->array()->keys([
        "street_addr1" => cmf()->string()->required()->min(2),
        "street_addr2" => cmf()->string()->optional()->min(2),
        "city"         => cmf()->string()->required()->min(2),
        "state"        => cmf()->string()->alternatives([
            [
                'is' => cmf()->string()->length(2),
                'then' => cmf()->string()->anyOf(array_keys($stateArray)),
                'else' => cmf()->string()->anyOf(array_values($stateArray))
            ],
        ])
    ])->required()
]);
```

The schema defined above validates the following:

- first\_name, last\_name:
    - must be a string
    - is required
    - contain only alpha (a-z) characters
    - a minimum of 1 character
- email:
    - must be a string
    - must be an email
    - is *optional*
- address:
    - must be an array
    - must have the following keys (also with their own validation)
        - street\_addr1, city:
            - must be a string
            - is required
            - contains at least 2 characters
        - street\_addr2:
            - must be a string
            - contains at least 2 characters
            - is *optional* (everything is optional unless made explicitly `required()`)
        - state:
            - *if* the string is exactly 2 characters, then:
                - the string may be any of the state short codes (e.g. FL)
            - *else* the string must be any of the state long forms (e.g. Florida)

Usage
-----

[](#usage)

Using Comfort entails defining your schema like we do above which returns a callable to be used like so:

```
$data = $registrationSchema($jsonData);
```

This will do two things:

- Run the validation stack
- Return the data as an array (see more on this below) or a `ValidationError` instance

Only the `json()` validator currently takes the liberty of automatically transforming your data, the other validators will currently return data in the type it was passed to.

See more at our API reference: [API.md](API.md)

Custom Validators
-----------------

[](#custom-validators)

When in need of business specific validations, the mechanism is simple. If for instance, the email validation must be changed to allow your custom validation schema it can be accomplished like so:

```
class CustomerStringValidator extends \Comfort\Validator\StringValidator {
        public function email()
        {
            return $this->add(function ($value, $nameKey) {
                if (strstr($value, 'test')) {
                    return $this->createError('string.email', $value, $nameKey);
                }
            });
        }
}

\Comfort\Comfort::registerValidator('string', CustomerStringValidator::class);
```

Subsequent calls to `cmf()->string()->email('test@gmail.com')` would run this new validator.

**Note:** validators *must* extend `\Comfort\Validator\AbstractValidator`

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 83.3% 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 ~1 days

Total

7

Last Release

3694d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/69551?v=4)[Andres Galindo](/maintainers/mrferos)[@mrferos](https://github.com/mrferos)

---

Top Contributors

[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (5 commits)")[![EdwardDrapkin](https://avatars.githubusercontent.com/u/6296006?v=4)](https://github.com/EdwardDrapkin "EdwardDrapkin (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mrferos-comfort/health.svg)

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

###  Alternatives

[stape/gtm-server-side-magento-module

Stape Conversion Tracking Magento Module

1368.1k](/packages/stape-gtm-server-side-magento-module)[chaoswey/taiwan-id-validator

台灣身分證、統一編號驗證

319.9k](/packages/chaoswey-taiwan-id-validator)

PHPackages © 2026

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