Skip to content

A modern Symfony-compatible Transfer Object Generator with property hooks, FixedArray, and asymmetric visibilities.

License

Notifications You must be signed in to change notification settings

picamator/transfer-object

Repository files navigation

Transfer Object Generator

CI workflow License PHP Version Require Symfony Compatibility Wiki Latest Stable Version

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 another 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:

Transfer Object:

  • implements methods:
    • fromArray()
    • toArray()
    • toFilterArray()
  • implements standard interfaces:
    • IteratorAggregate
    • JsonSerializable
    • Countable
  • supports embedded and collection Transfer Objects
  • supports PHP primitive data types
  • supports:
    • BackedEnum
    • DateTime
    • DateTimeImmutable
    • BcMath\Number
  • supports asymmetric property visibility
  • integrates external Transfer Objects

Installation

Composer installation:

$ composer require picamator/transfer-object

Examples

Usage Tests

Definition Files and Transfer Object generators have been tested against following APIs:

Scenario

  1. Rest API response is used as a blueprint to generate Definition Files
  2. Transfer Objects are generated based on Definition Files
  3. Transfer Object instance is created with the API response
  4. Transfer Object is converted back to the array
  5. The converted array is compared with the API response

In all cases, data 100% are matched ✅.

For detailed information, please check DefinitionGeneratorFacadeTest.

Documentation

For more details, please visit project's wiki.

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.

License

Transfer Object Generator is free and open-source software licensed under the MIT License.

For more details, please see the LICENSE file.