PHPackages                             c0de8/matchmaker - 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. c0de8/matchmaker

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

c0de8/matchmaker
================

Ultra-fresh PHP matching class (in PHP 7.x OOP)

2.0.5(8y ago)43.9k[1 issues](https://github.com/C0DE8/matchmaker/issues)MITPHPPHP &gt;=7.1

Since Jun 28Pushed 8y agoCompare

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

READMEChangelog (5)Dependencies (1)Versions (8)Used By (0)

matchmaker
==========

[](#matchmaker)

[![Total Downloads](https://camo.githubusercontent.com/d5f4bcf8a5adebc714cb15257c0f921b6af165a1b9410d91a8e2dd369d551dc3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63306465382f6d617463686d616b65722e737667)](https://packagist.org/packages/c0de8/matchmaker)[![Latest Stable Version](https://camo.githubusercontent.com/f5f0a6f0bdc368e74def8506e7e74e9cff33567aba12d6656b761d514ba53f4e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63306465382f6d617463686d616b65722e737667)](https://packagist.org/packages/c0de8/matchmaker)

[![License](https://camo.githubusercontent.com/167d26656ac9694ba0f279b425bfa0a668928d67c45465b06fc50fa69da480d4/68747470733a2f2f706f7365722e707567782e6f72672f63306465382f6d617463686d616b65722f6c6963656e7365)](https://packagist.org/packages/c0de8/matchmaker)

PHP Objects/methods that help you validate structure of complex nested PHP arrays. Like XML or JSON Schema.

```
use C0DE8\MatchMaker\Manager;

use C0DE8\MatchMaker\Exception\InvalidValueTypeException;
use C0DE8\MatchMaker\Exception\KeyMatcherFailException;
use C0DE8\MatchMaker\Exception\KeyMatchFailException;
use C0DE8\MatchMaker\Exception\MatcherException;

$books = [
    [
        'type'     => 'book',
        'title'    => 'Geography book',
        'chapters' => [
            'eu' => ['title' => 'Europe',  'interesting' => true],
            'as' => ['title' => 'America', 'interesting' => false]
        ],
        'price'    => 19.99
    ],
    [
        'type'     => 'book',
        'title'    => 'Foreign languages book',
        'chapters' => [
            'de' => ['title' => 'Deutsch']
        ],
        'price'    => 29.99
    ]
];

$pattern = [
    '*' => [
        'type'     => 'book',
        'title'    => ':string contains(book)',
        'chapters' => [
            ':string length(2) {1,3}' => [
                'title'        => ':string',
                'interesting?' => ':bool',
            ]
        ],
        'price'    => ':float'
    ]
];

try {

    (new Manager)->matchAgainst($books, $pattern); // return true (otherwise throws an exception)

} catch (\InvalidArgumentException $excetpion) {

    echo $exception->getMessage();

} catch (InvalidValueTypeException $excetpion) {

    echo $exception->getMessage();

} catch (KeyMatcherFailException $excetpion) {

    echo $exception->getMessage();

} catch (MatcherException $excetpion) {

    echo $exception->getMessage();

} catch (\Exception $excetpion) {

    echo $exception->getMessage();
}
```

It could be used to check scalar values, objects or arrays from different sources (JSON, XML, Post Data).

Matching rules
--------------

[](#matching-rules)

Matching rules are strings that **start** with '**:**' (*colon*). You can use multiple matchers joined with **space**. Matcher could be any callable (name of function or closure). You can add your own rules or replace standard ones.

- **General**

    - empty
    - nonempty
    - required
    - in(a, b, ...)
    - mixed
    - any
- **Types**

    - array
    - bool
    - boolean
    - callable
    - double
    - float
    - int
    - integer
    - long
    - numeric
    - number
    - object
    - real
    - resource
    - scalar
    - string
- **Numbers**

    - gt(n)
    - gte(n)
    - lt(n)
    - lte(n)
    - negative
    - positive
    - between(a, b)
- **Strings**

    - alnum
    - alpha
    - cntrl
    - digit
    - graph
    - lower
    - print
    - punct
    - space
    - upper
    - xdigit
    - regexp(pattern)
    - email
    - url
    - ip
    - length(n)
    - min(n)
    - max(n)
    - contains(needle)
    - starts(s)
    - ends(s)
    - json
    - date
- **Arrays**

    - count(n)
    - keys(key1, key2, ...)
- **Objects**

    - instance(class)
    - class\_exists(className)
    - property(name, value)
    - method(name, value)

More details you can find [here](https://github.com/C0DE8/matchmaker/blob/master/src/C0DE8/Matchmaker/Rules.php)

Quantifiers for keys
--------------------

[](#quantifiers-for-keys)

- **!** - one key required (default)
- **?** - optional key
- \* - any count of keys
- **{3}** - strict count of keys
- **{1,5}** - range

For matchers (i.e. ':string') default quantifier is \*

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

[](#installation)

- Install matchmaker via composer for your project:

**stable**

```
composer require c0de8/matchmaker:*

```

**development**

```
composer require c0de8/matchmaker:dev-master

```

PHPUnit
-------

[](#phpunit)

This package expects (uses) PHPUnit Version 6.x.x. [Site](https://phpunit.de/)

*(but PHPUnit Version 5.x.x also works)*

License
-------

[](#license)

Copyright (c) 2017 Bjoern Ellebrecht

Copyright (c) 2014 Petr Trofimov

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

30

—

LowBetter than 65% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 55% 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 ~175 days

Recently: every ~0 days

Total

7

Last Release

3282d ago

Major Versions

1.0 → 2.02017-05-13

PHP version history (3 changes)1.0PHP &gt;=5.4

2.0PHP &gt;=7

2.0.5PHP &gt;=7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/6300b12e7bc87d897d70fbd238dcd6f0ece06c57a77e8cb9fe8eda9ca08139d8?d=identicon)[C0DE8](/maintainers/C0DE8)

---

Top Contributors

[![ptrofimov](https://avatars.githubusercontent.com/u/867178?v=4)](https://github.com/ptrofimov "ptrofimov (44 commits)")[![C0DE8](https://avatars.githubusercontent.com/u/20956699?v=4)](https://github.com/C0DE8 "C0DE8 (27 commits)")[![cdrubin](https://avatars.githubusercontent.com/u/232306?v=4)](https://github.com/cdrubin "cdrubin (9 commits)")

---

Tags

arraycompareexceptionmatchmatchingpatternphpphp71schemastructurejsonschemavalidationarraypatternmatchermatchmaker

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/c0de8-matchmaker/health.svg)

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

###  Alternatives

[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[ptrofimov/matchmaker

Ultra-fresh PHP matching functions

27167.7k](/packages/ptrofimov-matchmaker)[league/config

Define configuration arrays with strict schemas and access values with dot notation

564302.2M24](/packages/league-config)[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[jbzoo/data

An extended version of the ArrayObject object for working with system settings or just for working with data arrays

891.6M23](/packages/jbzoo-data)[lezhnev74/pasvl

Array Validator (regular expressions for nested array, sort of)

5253.7k3](/packages/lezhnev74-pasvl)

PHPackages © 2026

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