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

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

cdrubin/matchmaker
==================

Ultra-fresh PHP matching functions

1.0(11y ago)7363MITPHPPHP &gt;=5.4

Since Jun 28Pushed 8y agoCompare

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

READMEChangelogDependencies (1)Versions (2)Used By (0)

```
NOTE!

I've found enough issues in this library to not use it.
It remains here for historical purposes but I
would not recommend anyone expect it to work reliably as-is.

```

matchmaker
==========

[](#matchmaker)

PHP functions that help you validate structure of complex nested PHP arrays.

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

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

matchmaker\matches($books, $pattern); // true
```

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 ':'. 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)
- property(name, value)
- method(name, value)

More details you can find [here](https://github.com/ptrofimov/matchmaker/blob/master/src/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:

```
composer require ptrofimov/matchmaker:*

```

License
-------

[](#license)

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

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 81.5% 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

Unknown

Total

1

Last Release

4343d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

jsonschemavalidationarraypatternmatchermatchmaker

###  Code Quality

TestsPHPUnit

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/cdrubin-matchmaker/health.svg)](https://phpackages.com/packages/cdrubin-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)
