PHPackages                             mackrais-organization/property-transform - 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. mackrais-organization/property-transform

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

mackrais-organization/property-transform
========================================

A PHP library for transforming DTO properties using attributes with support for PHP functions, DI services, and nested object transformation.

v1.0.0(1y ago)01MITPHPPHP &gt;=8.3CI passing

Since Mar 15Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mackrais-organization/property-transform)[ Packagist](https://packagist.org/packages/mackrais-organization/property-transform)[ Docs](https://github.com/mackrais-organization/property-transform)[ GitHub Sponsors](https://github.com/mackrais)[ RSS](/packages/mackrais-organization-property-transform/feed)WikiDiscussions master Synced 1mo ago

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

PHP Property Transform
======================

[](#php-property-transform)

[![Scrutinizer Quality Score](https://camo.githubusercontent.com/d02391dae70f10649613a4522ac19f862f56811e842f63e2ba4dbab5e9136b93/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mackrais-organization/property-transform/)[![Build Status](https://camo.githubusercontent.com/3057299d0b983ac94f67bc2ab585f189233c7a41cd160b4be795acdd22066351/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f63692e79616d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/mackrais-organization/property-transform/actions?query=workflow%3ACI+branch%3Amaster+)[![License](https://camo.githubusercontent.com/d1665998755de5573efb177047177456fcae99be8ec49185ed8f5937ee7759e0/687474703a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f6c6963656e7365)](https://packagist.org/packages/mackrais-organization/property-transform)[![Latest Stable Version](https://camo.githubusercontent.com/663c8b2ac954636022b6cc2a7a64b80a9a65508ed2d740a4bde333676bfd56e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mackrais-organization/property-transform)[![Latest Unstable Version](https://camo.githubusercontent.com/c872ef709fd2df7a97e7a99f39091a4df479409614942c07496a0d62e83845ef/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f762f756e737461626c65)](https://packagist.org/packages/mackrais-organization/property-transform)[![CodeCov](https://camo.githubusercontent.com/6fa6772033be92a3440567c3445724594b0d7d6658cb687aebd942f30168e90d/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2e7376673f7374796c653d666c61742d737175617265)](https://codecov.io/github/mackrais-organization/property-transform)[![StyleCI](https://camo.githubusercontent.com/4c8f157d76490962c8b23cd0a9214a635916f7eeeccc9ebf142567d61e7fa5e5/68747470733a2f2f7374796c6563692e696f2f7265706f732f3133393732313431362f736869656c643f7374796c653d666c61742d737175617265)](https://styleci.io/repos/139721416)[![Gitter](https://camo.githubusercontent.com/38615bd37fa667fefc3415d970da6c8f0de8796527cb97a89dfc59435f3189bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6769747465722d6a6f696e253230636861742d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://gitter.im/mackrais-organization/property-transform)[![Total Downloads](https://camo.githubusercontent.com/a0ea1739f3fa82a982016145b541359825a2709cf6ca09701a799850fe4ecbd1/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f646f776e6c6f616473)](https://packagist.org/packages/mackrais-organization/property-transform)[![Monthly Downloads](https://camo.githubusercontent.com/3d7f491339b168b2f6753754f7d91f7bb1964094bbebcea477efd8a9363911e6/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f642f6d6f6e74686c79)](https://packagist.org/packages/mackrais-organization/property-transform)[![Daily Downloads](https://camo.githubusercontent.com/8bedd72c7dfac1012df700d53c5e31a25e839920db40621e56d7eef27ed849ab/68747470733a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f642f6461696c79)](https://packagist.org/packages/mackrais-organization/property-transform)[![PHP Version Require](https://camo.githubusercontent.com/4ef344dd525d6248dd3da3cd9122e58c563d3a2f326d86fd9ffb3afef9a28e07/687474703a2f2f706f7365722e707567782e6f72672f6d61636b726169732d6f7267616e697a6174696f6e2f70726f70657274792d7472616e73666f726d2f726571756972652f706870)](https://packagist.org/packages/mackrais-organization/property-transform)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#)

Overview
--------

[](#overview)

The **Property Transform** library provides a powerful way to automatically transform DTO properties using **PHP attributes**.
This allows you to apply transformations such as trimming, formatting, and sanitization **directly on properties**, while also supporting **nested object transformation** and **dependency injection**.

### 🔥 Features

[](#-features)

- ✅ **Transform DTO properties using PHP attributes**
- ✅ **Supports multiple transformations per property** (e.g., trim + lowercase)
- ✅ **Applies transformations to nested objects automatically**
- ✅ **Supports callable PHP functions (`trim`, `strtolower`, etc.)**
- ✅ **Works with Dependency Injection (DI) for custom transformations**
- ✅ **Supports class methods as transformers (`[ClassName::class, 'method']`)**
- ✅ **Lightweight &amp; efficient – no runtime overhead**

---

📌 Table of Contents
-------------------

[](#-table-of-contents)

- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Dependency Injection Support](#dependency-injection-support)
- [License](#license)

---

🛠 Installation
--------------

[](#-installation)

Install via **Composer**:

```
composer require mackrais-organization/property-transform
```

---

🚀 Usage
-------

[](#-usage)

### 1️⃣ **Basic DTO Transformation**

[](#1️⃣-basic-dto-transformation)

You can use built-in PHP functions as transformers by adding attributes:

```
use MackRais\PropertyTransform\Transform;

class UserDto
{
    #[Transform('trim')]
    #[Transform('strtolower')]
    public string $name;

    #[Transform('intval')]
    public string $age;
}
```

Then, apply transformations:

```
$dto = new UserDto();
$dto->name = '  John Doe ';
$dto->age = '25';

$dataTransformer = new DataTransformer(new TransformerFactory($container));
$dataTransformer->transform($dto);

echo $dto->name; // Output: "john doe"
echo $dto->age; // Output: 25 (converted to integer)
```

---

🎯 Examples
----------

[](#-examples)

### 2️⃣ **Nested DTO Transformation**

[](#2️⃣-nested-dto-transformation)

If a DTO contains another DTO, transformations will apply recursively:

```
class AddressDto
{
    #[Transform('trim')]
    #[Transform('strtolower')]
    public string $city;
}

class UserDto
{
    #[Transform('trim')]
    #[Transform('strtolower')]
    public string $name;

    #[Transform] // Required for nested transformation
    public AddressDto $address;
}
```

Usage:

```
$address = new AddressDto();
$address->city = '  New York ';

$dto = new UserDto();
$dto->name = '  Jane Doe ';
$dto->address = $address;

$dataTransformer->transform($dto);

echo $dto->name; // Output: "jane doe"
echo $dto->address->city; // Output: "new york"
```

---

### 3️⃣ **Using Class Methods as Transformers**

[](#3️⃣-using-class-methods-as-transformers)

You can also define a custom transformer method inside a class:

```
class SecuritySanitizer
{
    public function sanitize(?string $input): string
    {
        return strip_tags((string) $input);
    }
}
```

And use it as a transformer:

```
class UserDto
{
    #[Transform([SecuritySanitizer::class, 'sanitize'])]
    public string $bio;
}
```

---

🏗 Dependency Injection Support
------------------------------

[](#-dependency-injection-support)

Transformers can be registered as **public services** in Symfony or any DI container.

Example using **PSR-11 Container**:

```
use Psr\Container\ContainerInterface;

$container = new SomePsr11Container();
$factory = new TransformerFactory($container);
$dataTransformer = new DataTransformer($factory);
```

Now, any **service-based transformer** (like `SecuritySanitizer`) will be **automatically resolved**.

---

📜 License
---------

[](#-license)

**Property Transform** is released under the **MIT License**. See the [`LICENSE.md`](LICENSE.md) file for details.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance47

Moderate activity, may be stable

Popularity1

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

Unknown

Total

1

Last Release

420d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/488beefc5336c7cda0467a3c200e1d1d9ae6fe68639549b6b19179c8db74e3c7?d=identicon)[MackRais](/maintainers/MackRais)

---

Top Contributors

[![mackrais](https://avatars.githubusercontent.com/u/8103057?v=4)](https://github.com/mackrais "mackrais (2 commits)")

---

Tags

dependency-injectiontransformdtodata-transformerphp-attributes

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mackrais-organization-property-transform/health.svg)

```
[![Health](https://phpackages.com/badges/mackrais-organization-property-transform/health.svg)](https://phpackages.com/packages/mackrais-organization-property-transform)
```

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[ecotone/ecotone

Supporting you in building DDD, CQRS, Event Sourcing applications with ease.

558549.8k17](/packages/ecotone-ecotone)[flow-php/etl

PHP ETL - Extract Transform Load - Abstraction

374468.4k50](/packages/flow-php-etl)[level-2/dice

A minimalist Dependency injection container (DIC) for PHP. Please note: 3.0+ is only compatible with PHP 7.0. The 2.0 branch is compatbile with PHP 5.6.

437730.3k17](/packages/level-2-dice)[nutgram/hydrator

Hydrator for PHP 8.0+

12265.2k6](/packages/nutgram-hydrator)[mattketmo/camel

Tiny library to handle words case transformation

29357.0k17](/packages/mattketmo-camel)

PHPackages © 2026

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