Skip to content

Transfer Object Generator based on property hooks and SplFixedArray

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 Latest Stable Version

Transfer Object Generator

Would you like to build lightweight Transfer Objects (TO) easily? You're in the right place!

Build TOs Using an Array as Blueprint

Imagine you have an array:

$data = [
    'firstName' => 'Jan',
    'lastName' => 'Kowalski'
];

TO facade method helps to convert array into YML definition file:

Customer:
  firstName:
    type: string
  lastName:
    type: string

Generator console command builds TO based on definition file:

$customerTransfer = new CustomerTransfer();
$customerTransfer->firstName = 'Jan';
$customerTransfer->lastName = 'Kowalski';

How it works in action can be found on Wiki:

Key Features

  • Interface methods: implements fromArray(), toArray()
  • Standard interfaces: implements IteratorAggregate, JsonSerializable, and Countable
  • Lightweight: TO includes only data without any business logic
  • Nullable: supports both attribute types nullable and not nullable (required:)
  • BackedEnum: supports BackedEnum
  • Adaptable: compatible with custom Data Transfer Object (DTO) implementation

Installation

Composer installation:

$ composer require picamator/transfer-object

Usage

Terminal

Run command bellow to generate Transfer Objects:

$ ./vendor/bin/generate-transfer [-c|--configuration CONFIGURATION]

Please check Wiki for more details:

Facade Interface

Facade interface DefinitionGeneratorFacadeInterface is used to generate YML definition file based on array.

Please check Wiki for more details:

Acknowledgment

Many thanks for your contribution, supports, feedback and simply using Transfer Object Generator!

Contribution

If you find this project useful, please add a star to 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 or submit a pull request. Here is a Contribution Guide.

Please note that 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.