PHPackages                             ilsenem/matcher - 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. ilsenem/matcher

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

ilsenem/matcher
===============

Array schema matcher

v1.0.0(9y ago)440MITPHP

Since Nov 21Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ilsenem/matcher)[ Packagist](https://packagist.org/packages/ilsenem/matcher)[ Docs](https://github.com/ilsenem/matcher)[ RSS](/packages/ilsenem-matcher/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (1)Versions (2)Used By (0)

Matcher\\Schema
===============

[](#matcherschema)

Simple schema matcher for arrays.

- [Installation](#installation)
- Usage
    - [Type matching](#type-matching)
    - [Nullable values](#type-matching)
    - [Skip keys](#skip-keys)
    - [Composite arrays](#composite-arrays)
    - [Array nesting and collections](#array-nesting-and-collections)
- [Errors](#errors)

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

[](#installation)

Install as [Composer](http://getcomposer.org) dependency:

```
composer require ilsenem/matcher
```

In your code:

```
use Matcher\Schema;

// $schema = [];
// $data   = [];

$matcher = new Schema($schema);

if (!$matcher->match($data)) {
    print_r($matcher->getErrors());
}
```

Usage
-----

[](#usage)

### Type matching

[](#type-matching)

Supported types for values are:

- boolean
- integer
- double
- string

```
$schema = [
    'id'     => 'integer',
    'email'  => 'string',
    'active' => 'boolean',
    'rating' => 'double',
];

$matcher = new Matcher\Schema($schema);

$matcher->match([
    'id'     => 1,
    'email'  => 'some@domain.zone',
    'active' => true,
    'rating' => .5,
]);
```

### Nullable values

[](#nullable-values)

Add `?` before type declaration to mark value as nullable.

```
$schema = [
    'id'       => 'integer',
    'email'    => 'string',
    'nickname' => '?string',
];

$matcher = new Schema($schema);

$matcher->match([
    'id'       => 7,
    'email'    => 'leeroy.jenkins@wow.lol',
    'nickname' => null,
]);
```

### Skip keys

[](#skip-keys)

Add `?` before key to skip matching if key is not present in data.

```
$schema = [
    'id'        => 'integer',
    'email'     => 'string',
    '?optional' => 'boolean'
];

$matcher = new Schema($schema);

$matcher->match([
    'id'    => 18,
    'email' => 'tired.to.fake@emails.zone',
]);
```

### Composite arrays

[](#composite-arrays)

If an array have no strict schema but follow typings for key and value, you could set composite `key => value` type for it:

```
$schema = [
    'rules' => 'string => boolean',
];

$matcher = new Schema($schema);

$matcher->match([
    'rules' => [
        'admin.cp'    => true,
        'admin.users' => true,
    ],
]);
```

### Array nesting and collections

[](#array-nesting-and-collections)

You could nest schema one into another to match complex structures and match array collections:

```
$schema = [
    '*' => [ // Many users in collection
        'id'     => 'integer',
        'email'  => 'string',
        'active' => 'boolean',
        'tokens' => [ // Nest more rules
            'activation'    => '?string',
            'authorization' => '?string',
        ],
        'role' => [
            'id'        => 'integer',
            'title'     => 'string',
            'superuser' => 'boolean',
            '?rules'    => 'string => boolean',
        ],
        '?orders' => [
            '*' => [
                'id'       => 'integer',
                'quantity' => 'integer',
                'price'    => 'double',
            ],
        ],
    ],
];

$matcher = new Schema($schema);

$matcher->match([
    [
        'id'     => 1,
        'email'  => 'admin@domain.zone',
        'active' => true,
        'tokens' => [
            'activation'    => null,
            'authorization' => '0329a06b62cd16b33eb6792be8c60b158d89a2ee3a876fce9a881ebb488c0914',
        ],
        'role' => [
            'id'    => 1,
            'title' => 'Administrator',
        ],
    ],
    [
        'id'     => 2,
        'email'  => 'moderator@domain.zone',
        'active' => true,
        'tokens' => [
            'activation'    => null,
            'authorization' => null,
        ],
        'role' => [
            'id'    => 2,
            'title' => 'Moderator',
            'rules' => [
                'admin.cp'     => false,
                'moderator.cp' => true,
            ],
        ]
    ],
    [
        'id'     => 87,
        'email'  => 'customer@domain.zone',
        'active' => true,
        'tokens' => [
            'activation'    => null,
            'authorization' => null,
        ],
        'role' => [
            'id'    => 3,
            'title' => 'Customer',
            'rules' => [
                'admin.cp'     => false,
                'moderator.cp' => false,
            ],
        ],
        'orders' => [
            [
                'id'       => 873,
                'quantity' => 7,
                'price'    => 18.99,
            ],
            [
                'id'       => 1314,
                'quantity' => 19,
                'price'    => 1.97,
            ]
        ],
    ]
]);
```

Errors
------

[](#errors)

With `$matcher->getErrors()` after matching you could get array of errors:

```
[
    'path.to.*.array.key' => [
        'TYPE_OF_ERROR' => 'Human readable description.',
    ],
    // ...
]
```

Types of errors:

- `Schema::ERR_COLLECTION_DEFINITION` - Definition of the collection must be the only definition of the level.
- `Schema::ERR_KEY_NOT_FOUND` - The key defined in the schema is not found in the data.
- `Schema::ERR_TYPE_UNKNOWN` - Unknown type given in schema.
- `Schema::ERR_TYPE_MISMATCH` - Type mismatch for any type of declaration.

License
-------

[](#license)

MIT.

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

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

3508d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8fd586ab664e58ea3808289a595c5c347e8c659bde6d71237bc678e7843f33d1?d=identicon)[ilsenem](/maintainers/ilsenem)

---

Top Contributors

[![ilsenem](https://avatars.githubusercontent.com/u/789712?v=4)](https://github.com/ilsenem "ilsenem (1 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")

### Embed Badge

![Health badge](/badges/ilsenem-matcher/health.svg)

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

###  Alternatives

[icap/html-diff

A PHP5 library that diffs (compares) HTML files.

29119.5k4](/packages/icap-html-diff)[mrsuh/php-bison-skeleton

PHP skeleton for Bison

3911.3k1](/packages/mrsuh-php-bison-skeleton)[ucomm/a11y-menu

A package to generate accessible main navigation menus. It includes: a js script for the browser as an npm package, WordPress walker for theme development, and WordPress plugin.

252.0k](/packages/ucomm-a11y-menu)[tatter/chat

Embedded chat widget for CodeIgniter 4

191.8k](/packages/tatter-chat)

PHPackages © 2026

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