PHPackages                             schemantic/schemantic - 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. [Database &amp; ORM](/categories/database)
4. /
5. schemantic/schemantic

ActiveLibrary[Database &amp; ORM](/categories/database)

schemantic/schemantic
=====================

Smart PHP structures

5.1.7(2mo ago)0489MITPHPPHP ^8.1

Since Jan 19Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Vchslv-Zkhrv/Schemantic)[ Packagist](https://packagist.org/packages/schemantic/schemantic)[ RSS](/packages/schemantic-schemantic/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (9)Versions (27)Used By (0)

Schemantic
==========

[](#schemantic)

Recursively parsing PHP structures. Pure PHP 8.1+, no dependencies

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

[](#installation)

```
composer require schemantic/schemantic

```

Simple example
--------------

[](#simple-example)

Schemas:

```
use Schemantic\Attribute\ArrayOf;
use Schemantic\Attribute\Validate;
use Schemantic\Attribute\Alias;
use Schemantic\Schema;

class Tag extends Schema
{
    public function __construct(
        #[Validate\GreaterThan(0)]
        public readonly int $id,

        #[Validate\NotEmpty]
        #[Alias('name')]
        public readonly stirng $title,

        #[Validate\Validator(ValidateHelper::class, 'validateColor')]
        public readonly ?string $color,
    ) {
    }
}

class Product extends Schema
{
    public function __construct(
        #[Validate\GreaterThan(0)]
        public readonly int $id,

        public readonly string $name,

        #[Timestamp]
        public readonly \DateTimeImmutable $createdAt,

        #[Timestamp]
        public readonly ?\DateTimeImmutable $deletedAt = null,

        #[Validate\GreaterThan(0)]
        public readonly ?float $price = null,

        #[ArrayOf(Tag::class)]
        #[Validate\Length(max: 3)]
        public readonly array $tags = [],
    ) {
    }
}
```

Data to read:

```
{
    "id": 123456789,
    "name": "test-product",
    "createdAt": 1771852144,
    "price": 12.3,
    "tags": [
        {
            "id": 1,
            "name": "tag1",
            "color": "#ffd900"
        },
        {
            "id": 2,
            "name": "tag2",
            "color": null
        }
    ]
}
```

Usage:

```
$raw = '{...}';  // the JSON from above

// easily switch between different formats
$responseData = Product::fromJSON($raw)->toArray(byAlias: true, dump: true, skipNulls: true);
```

```
$data = '[{...}, {...}]';  // array of JSONs from above

// read JSON as Product[], and exclude rows that do not pass validation
$rows = Product::fromJSONMultiple($data, validate: 'exclude');
```

```
$model = new \App\Models\Product();  // Laravel model / Doctrine Entity

// Update any object fields with an direct assignment and calling setters (::setName(), setPublic()). Virtual setters included
$schema = ...;
$schema->updateObject($model);
```

```
$model = ...;  // Laravel model / Doctrine Entity

// Read any object fields with direct access and calling getters (::getName(), ::getPublic()). Virtual getter included
$schema = Product::fromObject($model);
```

```
$schema = ...;

// Pass __construct params & set other properties after construction if needed
$model = Product::buildObject(\App\Models\Product::class);
```

Features:
---------

[](#features)

- **Recursive** sub-structures parsing (and arrays of sub-structures)
- Custom field **validation**, **parsing** and **dumping** via attributes
- Pre-defined fields validations
- Fields aliases
- ORM integration
- JSON parsing
- Enum dump &amp; parsing

Supported types:
----------------

[](#supported-types)

1. built-in PHP types
2. DateTimeInterface
3. UnitEnum and BackedEnum
4. Sub-schemas
5. Arrays of types above
6. Nullable types
7. Union types

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance88

Actively maintained with recent releases

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Recently: every ~10 days

Total

26

Last Release

63d ago

Major Versions

3.2.1 → 4.0.02025-09-07

4.1.1 → 5.0.02025-12-04

### Community

Maintainers

![](https://www.gravatar.com/avatar/89d1737ce5c4c6ce7f512d7c8e275ff38f7a62cdea3571695a629eff0703f49a?d=identicon)[vchslv-zkhrv](/maintainers/vchslv-zkhrv)

---

Top Contributors

[![Vchslv-Zkhrv](https://avatars.githubusercontent.com/u/124871799?v=4)](https://github.com/Vchslv-Zkhrv "Vchslv-Zkhrv (33 commits)")

---

Tags

jsonschemavalidationparserormmodelentitystructureparsingdtostructschemantic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[indaxia/doctrine-orm-transformations

Provides JSON-ready Doctrine ORM Entity-Array transfomtaions

12101.0k1](/packages/indaxia-doctrine-orm-transformations)

PHPackages © 2026

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