PHPackages                             kirillbdev/php-data-transformer - 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. kirillbdev/php-data-transformer

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

kirillbdev/php-data-transformer
===============================

Transform your data into typed objects

v1.1.0(4y ago)01.3kMITPHP

Since Jun 1Pushed 4y ago1 watchersCompare

[ Source](https://github.com/kirillbdev/php-data-transformer)[ Packagist](https://packagist.org/packages/kirillbdev/php-data-transformer)[ RSS](/packages/kirillbdev-php-data-transformer/feed)WikiDiscussions main Synced 3w ago

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

This package helps you to transform custom data into typed objects.

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

[](#installation)

### Using composer

[](#using-composer)

`composer require kirillbdev/php-data-transformer ^1.0.0`

Examples
--------

[](#examples)

### 1. Convert array of data to DTO

[](#1-convert-array-of-data-to-dto)

At first create simple DTO class.

```
namespace MyApp\Dto;

class UserDto
{
    public $id;

    public $firstname;
}
```

Now, using DataTransformer, let's transform an arbitrary data array into our DTO.

```
namespace MyApp;

use kirillbdev\PhpDataTransformer\DataTransformer;
use kirillbdev\PhpDataTransformer\DataObject\ArrayDataObject;
use MyApp\Dto\UserDto;

$dto = DataTransformer::transform(UserDto::class, new ArrayDataObject([
    'id' => 1,
    'firstname' => 'Jon'
]));
```

Class DtoTransfer will bypass all public properties of our Dto and automatically fetch values from input DataObject ( in our case it is an array). As you see, it's simple.

### 2. Receive custom keys from DataObject

[](#2-receive-custom-keys-from-dataobject)

There are situations when the keys of the input data differ from the property names of our DTO. In this case, we can receive data of the desired property using the `@ReceiveFrom` annotation.

```
namespace MyApp\Dto;

class UserDto
{
    public $id;

    /**
     * We need to receive this property from first_name key.
     * @ReceiveFrom("first_name")
     */
    public $firstname;
}
```

Now, try to transform data.

```
namespace MyApp;

use kirillbdev\PhpDataTransformer\DataTransformer;
use kirillbdev\PhpDataTransformer\DataObject\ArrayDataObject;
use MyApp\Dto\UserDto;

$dto = DataTransformer::transform(UserDto::class, new ArrayDataObject([
    'id' => 1,
    'first_name' => 'Jon' // Custom key that differ of our DTO property.
]));
```

### 3. Type casting

[](#3-type-casting)

You can specify which type you want to cast for certain properties in DTO. Use the `@Cast("type")` annotation for this. At this moment package support next types: int, float, bool.

```
namespace MyApp\Dto;

class UserDto
{
    /**
     * We want to cast this property to integer.
     * @Cast("int")
     */
    public $id;
}
```

You also can cast property to other typed object. For this you can use `@Cast()` annotation. I recommend you to use full class name for this (includes namespace).

```
namespace MyApp\Dto;

class UserDto
{
    /**
     * We want to cast this property to UserRoleDto.
     * @Cast()
     */
    public $role;
}
```

### 4. Custom transformation logic

[](#4-custom-transformation-logic)

Sometimes there are situations when you need to implement custom transformation logic of the desired property. In this case, you can implement an arbitrary transformation method for the desired property. The method must be named `transform{PropertyName}Property` and take a single argument `DataObjectInterface`, which is used to retrieve the data.

```
namespace MyApp\Dto;

use kirillbdev\PhpDataTransformer\Contracts\DataObjectInterface;

class UserDto
{
    public $id;

    /**
     * We need to receive this property as combination of two keys (firstname and lastname).
     */
    public $fullName;

    /**
     * Let's implement custom transformation method.
     *
     * @param DataObjectInterface $dataObject
     * @return string|null
     */
    public function transformFullNameProperty(DataObjectInterface $dataObject)
    {
        return $dataObject->get('firstname') . ' ' . $dataObject->get('lastname');
    }
}
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

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

Total

2

Last Release

1725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1ae5fb7d195731c95179725589337d469baec2fefa6798309a8d96facfa777be?d=identicon)[kirillbdev](/maintainers/kirillbdev)

---

Top Contributors

[![kirillbdev](https://avatars.githubusercontent.com/u/3593427?v=4)](https://github.com/kirillbdev "kirillbdev (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kirillbdev-php-data-transformer/health.svg)

```
[![Health](https://phpackages.com/badges/kirillbdev-php-data-transformer/health.svg)](https://phpackages.com/packages/kirillbdev-php-data-transformer)
```

###  Alternatives

[adfab/m2-module-gdpr

GDPR compatibility

632.2k](/packages/adfab-m2-module-gdpr)

PHPackages © 2026

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