mmouih/entity-generator

A tool designed to streamline the conversion of payloads (json, xml or yaml) into class entities

v1.0.2 2023-11-01 21:51 UTC

This package is auto-updated.

Last update: 2024-04-27 02:06:11 UTC


README

The Entity Generator is a tool designed to streamline the conversion of payloads into class entities for PHP applications running on PHP 7 and beyond. The generated entities adhere to the PSR-12 coding standards, ensuring a clean and consistent codebase.

This tool is particularly valuable for swiftly transforming payloads into Data Transfer Objects (DTOs), enhancing your PHP application's flexibility and efficiency.

Requirements

  • PHP 8.2 or higher

Usage

To leverage the Entity Generator, use the following command:

Using Json file

./phpgen generate [EntityName] [Payload] --f

Using Json string

./phpgen generate [EntityName] [Json] "json" 

Or simply

./phpgen generate [EntityName] [Json]

Example:

./phpgen generate User '{"id": 1, "label": "john"}'

Using XML file

./phpgen generate [EntityName] [filepath] "xml" -f

Using XML string

./phpgen generate [EntityName] [XML] "xml" 

Using Yaml file

./phpgen generate [EntityName] [filepath] "xml" -f

Configuration file

You can use customized entity generation options using a configuration a below,

#config.yaml.dist
entity.generator:
    output.dir: 'var/generated'
    namespace: 'Entity\Generated'
    property.phpdoc: true
    property.type: true # false before php7.4
./phpgen generate [EntityName] [filepath] "xml" -f -c path/to/config.yaml.dist

If config file is not configured, default options (config.yaml.dist) will be used.