PHPackages                             xepozz/remap - 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. xepozz/remap

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

xepozz/remap
============

1.0(2y ago)10PHP

Since Mar 16Pushed 2y ago1 watchersCompare

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

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

Remap
=====

[](#remap)

The library allows you to map data from the database to objects.

[![Latest Stable Version](https://camo.githubusercontent.com/9b527b8b3a2efc75de2fe0cf1987a3238f6e07e26e07fe169bec0029177f8ab7/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f72656d61702f762f737461626c652e737667)](https://packagist.org/packages/xepozz/remap)[![Total Downloads](https://camo.githubusercontent.com/57c0e9ec9d263f71275a8294ed425ec6917427e7e882e91fdfafbfc678e6aabb/68747470733a2f2f706f7365722e707567782e6f72672f7865706f7a7a2f72656d61702f646f776e6c6f6164732e737667)](https://packagist.org/packages/xepozz/remap)[![phpunit](https://github.com/xepozz/remap/workflows/PHPUnit/badge.svg)](https://github.com/xepozz/remap/actions)[![codecov](https://camo.githubusercontent.com/0dffa8525e74b3ac03785f40fb376e84c557646079a20a8cf1a864f1fb7bb62e/68747470733a2f2f636f6465636f762e696f2f67682f7865706f7a7a2f72656d61702f6272616e63682f6d61737465722f67726170682f62616467652e7376673f746f6b656e3d55524558414f5548544a)](https://codecov.io/gh/xepozz/remap)[![type-coverage](https://camo.githubusercontent.com/5b3b0fc08a46f0a7a9313a1514598f12cec440c3bf66e717134a27e5e09471a8/68747470733a2f2f73686570686572642e6465762f6769746875622f7865706f7a7a2f72656d61702f636f7665726167652e737667)](https://shepherd.dev/github/xepozz/remap)

Description
-----------

[](#description)

The main goal is to simplify the process of querying long SQL queries and mapping the result to objects.

The mapper is designed to be used with querying of many objects at once. It uses `\Generator` to fetch data from the database and map it to objects one by one, so it's memory efficient.

Under the hood, it uses:

- [yiisoft/db](https://github.com/yiisoft/db) to fetch data from the database
- [yiisoft/hydrator](https://github.com/yiisoft/hydrator) to map data to objects.

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

[](#installation)

```
composer req xepozz/remap
```

Usage
-----

[](#usage)

Pass a class name and a query to the `Remap`.

```
final class Todo
{
    public int $id;
    public string $title;
    public int $status;
    public int $created_at;
}
```

```
$sql = 'SELECT id, title, status, created_at FROM todo WHERE id = :id LIMIT 1';
$params = ['id' => 1];

$remap->map(Todo::class, $sql, $params); // returns \Generator of Todo objects
```

Hydration
---------

[](#hydration)

Using [yiisoft/hydrator](https://github.com/yiisoft/hydrator) brings benefits of the `Hydrator` library: [Attributes](https://github.com/yiisoft/hydrator/blob/master/docs/guide/en/mapping.md#using-attributes) to modify the behavior of the hydration process.

```
use Yiisoft\Hydrator\Attribute\Parameter\Data;
use Yiisoft\Hydrator\Attribute\SkipHydration;

final class TodoModelHydrator
{
    #[Data('id')]
    public string $identifier;
    #[Data('title')]
    public string $text;
    public string $status;
    #[Data('created_at')]
    public string $date_created;
}
```

Or any other attributes compatible with the `Hydrator` library.

### Tips

[](#tips)

#### Define query-related methods in the class

[](#define-query-related-methods-in-the-class)

```
final class Todo
{
    public int $id;
    public string $title;
    public int $status;
    public int $created_at;

    public static function selectOne(int $id): array
    {
        return [
            'SELECT id, title, status, created_at FROM todo WHERE id = :id LIMIT 1',
            ['id' => $id],
        ];
    }

    public static function selectAll(): string
    {
        return 'SELECT id, title, status, created_at FROM todo';
    }
}
```

And now it's easy to use:

```
$remap->map(Todo::class, ...Todo::selectOne(1)); // selectOne may return ['SELECT ...', ['id' => 1]]
$remap->map(Todo::class, Todo::selectOne(1)); // or shorter, without unpacking
$remap->map(Todo::class, Todo::selectAll());
$remap->map(...Todo::selectAll()); // selectAll may return [Todo::class, "SELECT ..."]
```

#### Unpack and store the result

[](#unpack-and-store-the-result)

```
$remap->map(...)
```

Always returns a generator. If you want to get an array of objects, use `iterator_to_array`:

```
$result = iterator_to_array(
    $remap->map(Todo::class, Todo::selectOne(1))
);
```

Or shorter:

```
$result = [...$remap->map(Todo::class, Todo::selectOne(1))];
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity41

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

791d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6815714?v=4)[Dmitrii Derepko](/maintainers/xepozz)[@xepozz](https://github.com/xepozz)

---

Top Contributors

[![xepozz](https://avatars.githubusercontent.com/u/6815714?v=4)](https://github.com/xepozz "xepozz (6 commits)")

---

Tags

hydratormappermapping

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

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

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

PHPackages © 2026

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