Download the PHP package mackrais-organization/property-transform without Composer
On this page you can find all versions of the php package mackrais-organization/property-transform. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mackrais-organization/property-transform
More information about mackrais-organization/property-transform
Files in mackrais-organization/property-transform
Package property-transform
Short Description A PHP library for transforming DTO properties using attributes with support for PHP functions, DI services, and nested object transformation.
License MIT
Homepage https://github.com/mackrais-organization/property-transform
Informations about the package property-transform
PHP Property Transform
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
- ✅ 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 & efficient – no runtime overhead
📌 Table of Contents
- Installation
- Usage
- Examples
- Dependency Injection Support
- License
🛠 Installation
Install via Composer:
🚀 Usage
1️⃣ Basic DTO Transformation
You can use built-in PHP functions as transformers by adding attributes:
Then, apply transformations:
🎯 Examples
2️⃣ Nested DTO Transformation
If a DTO contains another DTO, transformations will apply recursively:
Usage:
3️⃣ Using Class Methods as Transformers
You can also define a custom transformer method inside a class:
And use it as a transformer:
🏗 Dependency Injection Support
Transformers can be registered as public services in Symfony or any DI container.
Example using PSR-11 Container:
Now, any service-based transformer (like SecuritySanitizer
) will be automatically resolved.
📜 License
Property Transform is released under the MIT License. See the LICENSE.md
file for details.