PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Sergii Pryz   Transfer Object   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: Transfer Object
Generate transfer objects using property hooks
Author: By
Last change: Removed trailing comma from readme
Moved transfer-object image from .github to doc
Date: 6 days ago
Size: 3,722 bytes
 

Contents

Class file image Download

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: - Try Sample to generate Definition files - Try Sample to generate TOs - Try Advanced Sample to generate TOs

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: - Command Configuration - Definition File

Facade Interface

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

Please check Wiki for more details: - Facade Interfaces - Visualizing Diagrams

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.