PHPackages                             stamina/chequer-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. stamina/chequer-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

stamina/chequer-php
===================

Fast &amp; simple scalar/object/array checking/validation class

0.2.1(12y ago)873MITPHPPHP &gt;=5.3

Since Jan 30Pushed 12y ago1 watchersCompare

[ Source](https://github.com/panrafal/chequer-php)[ Packagist](https://packagist.org/packages/stamina/chequer-php)[ Docs](http://chequer.stamina.pl/)[ RSS](/packages/stamina-chequer-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (5)Used By (0)

Chequer 0.2
===========

[](#chequer-02)

**THE SPARKLING NEW LANGUAGE FOR CHECKING THINGS IN A SANE WAY**
Match scalars, arrays, objects and grumpy cats against the query of Your choice!

**Checkout the [chequer.stamina.pl](http://chequer.stamina.pl/) for more information**!

Oh wait! There is more!
-----------------------

[](#oh-wait-there-is-more)

Part of the package is `DynamicObject` class, which lets you **dynamically create classes** in PHP, **modify** object's **methods** on the fly, **extend objects** and moar! [Go check it out](/panrafal/chequer-php/blob/master/DynaminObject.md)! It's here to make typecasting easy, but it's pretty awesome on it's own!

---

Install
-------

[](#install)

Use [Composer](http://getcomposer.org/) package `stamina/chequer-php` to install.

The minimum required PHP version is 5.3. Because 5.4 introduces the shorthand array syntax - this version is recommended and used in this documentation.

```
php composer.phar require stamina/chequer-php

```

[![Build Status](https://camo.githubusercontent.com/4de63e756fa6c3c3e529062f4ecbeee179efb5d2ccacc37468a5314e6b99c846/68747470733a2f2f7472617669732d63692e6f72672f70616e726166616c2f636865717565722d7068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/panrafal/chequer-php)

---

Usage and examples
------------------

[](#usage-and-examples)

Usage
=====

[](#usage)

There are a couple of usage patterns to choose from.

Simple checks
-------------

[](#simple-checks)

For simple checks use static function `checkValue()`

```
if (Cheque::checkValue($value, $query)) {}
```

Reusing the query
-----------------

[](#reusing-the-query)

When you want to reuse your query, or pass it somewhere as a callback, create the object and call `check` method, or invoke the object.

```
// build the query object
$chequer = new Chequer($query);

// use it witch check()
if ($chequer->check($value)) {}

// or invoke it as a function
if ($chequer($value)) {}

// or pass it as a callback
array_filter($array, $chequer);
```

Global configuration
--------------------

[](#global-configuration)

You can store all your queries in configuration files and use them when they are needed. This way you can separate your validation/filtering logic from your code - just like you do with the templates!

```
// load the rules from the JSON file
Chequer::addGlobalRules(json_decode(file_get_contents('queries.json'), JSON_OBJECT_AS_ARRAY));

// reuse them
if (Chequer::checkValue($value, ['$rule' => 'some_defined_rule'])) {}
```

As every `query` is a `scalar` or an `array` - they can be easely stored in JSON, YAML, MongoDB - you name it.

Dependency injection
--------------------

[](#dependency-injection)

If you rather prefer DI - fret not. You can add rules to `Chequer` objects directly, which means you can make a factory, or pass the `Chequer` object around and still populate it with predefined rules.

The above example rewritten as Silex factory:

```
// load the queries once
$app['chequer.rules'] = $app->share(function() {
        return json_decode(file_get_contents('queries.json'), JSON_OBJECT_AS_ARRAY);
    });
// always have a fresh chequer on hand
$app['chequer'] = function() use ($app) {
    return (new Chequer())->addRules($app['chequer.rules']);
};

// reuse
if ($app['chequer']->query($value, ['$rule' => 'some_defined_rule'])) {}
```

---

Note, that the whole idea is very fresh. I've come up with the concept on January 29th, and made the lib the same day.
And that means - it *will* change!

©2013 Rafal Lindemann

[![githalytics.com alpha](https://camo.githubusercontent.com/3ba1db529196808df2cf6e30b79e8054bf28dee545e880fbfda63a85988397ed/68747470733a2f2f637275656c2d6361726c6f74612e7061676f6461626f782e636f6d2f6230373830373438303431323034633164323965353263383064383532666131 "githalytics.com")](http://githalytics.com/panrafal/chequer-php)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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 ~102 days

Total

3

Last Release

4652d ago

### Community

Maintainers

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

---

Top Contributors

[![panrafal](https://avatars.githubusercontent.com/u/1268900?v=4)](https://github.com/panrafal "panrafal (102 commits)")

---

Tags

phpcheckvalidationarraycallableobjectvalidatecallbackscalar

### Embed Badge

![Health badge](/badges/stamina-chequer-php/health.svg)

```
[![Health](https://phpackages.com/badges/stamina-chequer-php/health.svg)](https://phpackages.com/packages/stamina-chequer-php)
```

PHPackages © 2026

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