PHPackages                             ap-lib/scheme - 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. ap-lib/scheme

ActiveLibrary

ap-lib/scheme
=============

042PHP

Since Aug 6Pushed 9mo ago1 watchersCompare

[ Source](https://github.com/ap-lib/scheme)[ Packagist](https://packagist.org/packages/ap-lib/scheme)[ RSS](/packages/ap-lib-scheme/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

AP\\Scheme
==========

[](#apscheme)

[![MIT License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)

AP\\Scheme provides a structured framework for defining **data validation, transformation, and object conversion** in PHP.
It offers a set of interfaces and base classes that help implement **safe and consistent data handling** across applications

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

[](#installation)

```
composer require ap-lib/scheme
```

Features
--------

[](#features)

- **Data Transformation**: Convert objects to and from structured data formats.
- **Validation**: Implement validation rules and return meaningful error responses.
- **Error Handling**: Standardized error classes to track issues in transformation and validation.
- **Flexible Conversion**: Implement custom strategies for data serialization and deserialization.

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Getting started
---------------

[](#getting-started)

### Implementing `FromObject`

[](#implementing-fromobject)

This allows converting an object to a primitive representation

```
use AP\Scheme\FromObject;

class User implements FromObject
{
    public function __construct(
        private string $name,
        private int $age
    ) {}

    public function fromObject(): array
    {
        return [
            'name' => $this->name,
            'age'  => $this->age,
        ];
    }
}
```

### Implementing `ToObject`

[](#implementing-toobject)

This allows constructing an object from structured data.

```
use AP\Scheme\ToObject;
use AP\ErrorNode\ThrowableErrors

class User implements ToObject
{
    public function __construct(
        private string $name,
        private int $age
    ) {}

    public static function toObject(array|string|int|float|bool|null $data): static
    {
        if (!is_array($data) || !isset($data['name'], $data['age'])) {
            throw new ThrowableErrors([new BaseError("Invalid input data")]);
        }

        return new self($data['name'], $data['age']);
    }
}
```

### Implementing Validation

[](#implementing-validation)

This ensures the object maintains a valid internal state

```
use AP\Scheme\Validation;
use AP\ErrorNode\Error;
use AP\ErrorNode\Errors;

class User implements Validation
{
    public function __construct(
        private string $name,
        private int $age
    ) {}

    public function isValid(): true|DataErrors
    {
        $errors = [];

        if (empty($this->name)) {
            $errors[] = new Error("Name cannot be empty", ["name"]);
        }

        if ($this->age < 0) {
            $errors[] = new Error("Age must be a positive integer", ["age"]);
        }

        return empty($errors) ? true : new Errors($errors);
    }
}
```

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance43

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity13

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/1215fe5ecc9ba0ab1c730d3c992125cf6ebf460562e66be71ebae127789d465a?d=identicon)[AntonPanfilov](/maintainers/AntonPanfilov)

---

Top Contributors

[![anton-panfilov](https://avatars.githubusercontent.com/u/1083546?v=4)](https://github.com/anton-panfilov "anton-panfilov (7 commits)")

### Embed Badge

![Health badge](/badges/ap-lib-scheme/health.svg)

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

PHPackages © 2026

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