picamator / transfer-object
A modern Symfony-compatible Transfer Object Generator with property hooks, FixedArray, and asymmetric visibilities.
Installs: 52
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 1
Forks: 2
Open Issues: 0
pkg:composer/picamator/transfer-object
Requires
- php: >=8.5
- composer-runtime-api: ^2.2
- symfony/console: ^8.0
- symfony/filesystem: ^8.0
- symfony/finder: ^8.0
- symfony/yaml: ^8.0
Requires (Dev)
- captainhook/captainhook: ^5.27
- phpstan/phpstan: ^2.1
- phpstan/phpstan-strict-rules: ^2.0
- phpunit/phpunit: ^12.4
- slevomat/coding-standard: ^8.24
- squizlabs/php_codesniffer: ^4.0
- symfony/validator: ^8.0
- symfony/var-dumper: ^8.0
Suggests
- ext-bcmath: Provides support for 'numberType'.
- symfony/validator: Adds support for attribute asserts using the 'sf-assert' shortcut.
This package is auto-updated.
Last update: 2026-01-22 20:11:44 UTC
README
Transfer Object Generator
Would you like to build Symfony-compatible Transfer Objects?
You're in the right place! 🎉
Imagine you have a Rest API response:
{
"firstName": "Jan",
"lastName": "Kowalski"
}
Running the following interactive console command:
$ ./vendor/bin/definition-generate
Generates a YML definition file:
Customer: firstName: type: string lastName: type: string
Then, running console command:
$ ./vendor/bin/transfer-generate [-c|--configuration CONFIGURATION]
Builds the Transfer Object:
$customerTransfer = new CustomerTransfer(); $customerTransfer->firstName = 'Jan'; $customerTransfer->lastName = 'Kowalski';
Key Features
Symfony Compatability:
- Provides Symfony console command:
- Includes Symfony services:
- Enables automatic Symfony request query data mapping
- Supports Symfony validator attributes
Transfer Object:
- Offers methods:
fromArray()toArray()
- Implements standard interfaces:
IteratorAggregateJsonSerializableCountable
- Handles embedded and collection Transfer Objects.
- Works with PHP primitive data types.
- Extends compatibility to advanced types:
BackedEnumDateTimeDateTimeImmutableBcMath\Number
- Supports asymmetric property visibility.
- Integrates with external Transfer Objects.
Installation
Composer installation:
$ composer require picamator/transfer-object
| Version | PHP | Symfony |
|---|---|---|
| 4.0.0 | 8.4 | 7.3 |
| 5.0.0 | 8.5 | 8.0 |
Examples
Usage Tests
Definition Files and Transfer Object generators have been tested against the following APIs:
- NASA Open Api
- OpenWeather
- Content API for Shopping
- Frankfurter is a free, open-source currency data API
- Tagesschau API
- Statistisches Bundesamt (Destatis)
Scenario
- Rest API response is used as a blueprint to generate Definition Files
- Transfer Objects are generated based on Definition Files
- Transfer Object instance is created with the API response
- Transfer Object is converted back to the array
- The converted array is compared with the API response
For all APIs, data are ✅ matched.
For detailed information, please check DefinitionGeneratorFacadeTest.
Documentation
For more details, please visit Project's Wiki.
Publications
Acknowledgment
Many thanks ❤️ for your contribution, support, feedback and simply using the Transfer Object Generator!
Contribution
If you find this project useful, please ⭐ star the repository. Follow the project to stay updated with all activities.
If you have suggestions for improvements or new features, feel free to:
- Create an issue
- Submit a pull request
Here is a Contribution Guide.
This project is released with a Code of Conduct. By participating in this project and its community, you agree to abide by those terms.
Security Commitment
The project applies OpenSSF Best Practices.
For reporting security vulnerabilities, please follow Security Policy.
License
Transfer Object Generator is free and open-source software licensed under the MIT License.
For more details, please see the LICENSE file.
