PHPackages                             north/schema - 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. north/schema

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

north/schema
============

A simple schema validation package

v1.0.0(7y ago)12MITPHPPHP ^7.1

Since Feb 8Pushed 7y ago2 watchersCompare

[ Source](https://github.com/northphp/schema)[ Packagist](https://packagist.org/packages/north/schema)[ RSS](/packages/north-schema/feed)WikiDiscussions master Synced 3d ago

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

Schema
======

[](#schema)

[![Build Status](https://camo.githubusercontent.com/e419e48928098f38386f00683c2ba0caf15523e8413f43812ca06f52eae99ede/68747470733a2f2f7472617669732d63692e6f72672f6e6f7274687068702f736368656d612e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/northphp/schema)

A simple schema validation package.

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

[](#installation)

```
composer require north/schema

```

Examples
--------

[](#examples)

Basic validation of an array.

```
use North\Schema\Schema;

$schema = new Schema([
    'name' => 'string',
    'age' => 'int',
]);

// validate input against schema.
// returns bool or throws exception.
$schema->valid([
    'name' => 'fredrik',
    'age' => 27,
]);
```

Class validation converts class to array and validates public properties.

```
use North\Schema\Schema;

class User
{
    public $name = '';

    public function __construct($o)
    {
        foreach ($o as $k => $v) {
            $this->$k = $v;
        }
    }
}

$schema = new Schema([
    'name' => 'string',
]);

// validate input against schema.
// returns bool or throws exception.
$schema->valid(
    new User([
        'name' => 'fredrik',
    ]),
);
```

Types
-----

[](#types)

- array
- bool/boolean
- callable
- closure
- function
- implements (implements:INTERFACE)
- int/integer
- iterable
- float
- string
- object
- resources
- type (type:CLASS)

Types can take arguments, for example for implements and type:

```
[
    'person' => 'type:Person',
    'implements' => 'implements:Stringable',
]
```

Custom types
------------

[](#custom-types)

```
$schema->addType('custom_string', function($value) {
    return is_string($value);
});
```

When using extra arguments for types you just takes in more arguments.

```
$schema->addType('type', function ($t, string $expected) {
    return get_class($t) === $expected;
});
```

More examples in the [`tests/SchemaTest.php`](tests/SchemaTest.php)

License
-------

[](#license)

MIT © [Fredrik Forsmo](https://github.com/frozzare)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

2652d ago

### Community

Maintainers

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

---

Top Contributors

[![frozzare](https://avatars.githubusercontent.com/u/14610?v=4)](https://github.com/frozzare "frozzare (8 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/north-schema/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[nette/forms

📝 Nette Forms: generating, validating and processing secure forms in PHP. Handy API, fully customizable, server &amp; client side validation and mature design.

54013.2M450](/packages/nette-forms)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)

PHPackages © 2026

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