DTO Generator - PHP library for generating DTO classes

Overview

DTO Generator

PHP library for generating DTO classes.

Installation

Use the package manager composer to install micro/dto.

composer require micro/dto

Usage

Declare all required classes in the XML Schemes

  • example.xml
  • See the full list of possible options in the XSD scheme
">
xml version="1.0"?>
<dto xmlns="micro:dto-01"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="micro:dto-01 https://raw.githubusercontent.com/Micro-PHP/dto/master/src/Resource/schema/dto-01.xsd">
    <class name="User\User">
        <property name="email" type="string"/>
        <property name="age" type="int"/>
        <property name="updatedAt" type="datetime" />
        <property name="parent" type="User\User" /> 
    class>
dto>
  • And run generator
use Micro\Library\DTO\ClassGeneratorFacadeDefault;

$classGenerator = new ClassGeneratorFacadeDefault(
    ['./example.xml'],    // List of class declaration files
    './out',              // Path to the folder where to generate 
    'Transfer'            // Suffix for the all DTO classes (optional)
);

$classGenerator->generate();
  • Example usages
// Create new User object
$user = new UserTransfer();

//Restore User object from array
$user = new UserTransfer([
   'email'   => '[email protected]',
   'age'     => 32,
   'updatedAt'  => new \DateTime('11.04.2022 15:30'),
   'parent'  => [
       'email'  => '[email protected]',
       'age'    => 53,
   ]
]);

$user->getParent()->getEmail(); // [email protected]
// OR
$user['parent']['email']; // [email protected]


$user->setAge(33);
//OR
$user['age'] = 33;

// Serialize to JSON
$json = json_encode($user);

// Iterate as array
foreach ($user as $property => $value) {
    doSomethind();
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

You might also like...
Collection of PHP functions, mini classes and snippets for everyday developer's routine life

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

Um repositório com classes, interfaces para padronizar os projetos de PHP da empresa

php-utils PHP Utilities for Laravel/Lumen Installation cd /path/to/your/project composer require logcomex/php-utils Utilities Packages Contracts Excep

[READ-ONLY] CakePHP Utility classes such as Inflector, Text, Hash, Security and Xml. This repo is a split of the main code that can be found in https://github.com/cakephp/cakephp

CakePHP Utility Classes This library provides a range of utility classes that are used throughout the CakePHP framework What's in the toolbox? Hash A

A set of classes to create and manipulate HTML objects abstractions

HTMLObject HTMLObject is a set of classes to create and manipulate HTML objects abstractions. Static calls to the classes echo Element::p('text')-cla

Enforce that your classes get only instantiated by the factories you define!

Enforce that your classes get only instantiated by the factories you define!

Set of classes and tools to communicate with a Noso wallet using NosoP

NosoPHP Set of classes and tools to communicate with a Noso wallet using NosoP(Noso Protocol) Examples Node Info include __DIR__ . '/vendor/autoload.p

This component provides a collection of functions/classes using the symfony/intl package when the Intl extension is not installed.

Symfony Polyfill / Intl: ICU This package provides fallback implementations when the Intl extension is not installed. It is limited to the "en" locale

bin/magento command to display configured preferences for classes or interfaces

bin/magento command to display configured preferences for classes or interfaces A bin/magento command that will show you the configured preferences fo

this starter kite inspired by laravel & Geo and mvc pattern. it's wrap for Wordpress built in classes.

WordpressStarterKite Introduction Built With Prerequisite Directory Structure Guidelines Getting Started Authors Introduction this starter kite inspir

Releases(1.0.5)
Owner
Micro PHP Framework
Micro PHP Framework
A comprehensive library for generating differences between two strings in multiple formats (unified, side by side HTML etc). Based on the difflib implementation in Python

PHP Diff Class Introduction A comprehensive library for generating differences between two hashable objects (strings or arrays). Generated differences

Chris Boulton 708 Dec 25, 2022
Optimizes class loading performance by generating a single PHP file containing all of the autoloaded files.

Class Preloader for PHP This tool is used to generate a single PHP script containing all of the classes required for a specific use case. Using a sing

Class Preloader 356 Nov 26, 2022
A wrapper around symplify/config-transformer used to update recipes and using easy coding standard for generating readable config files.

Symfony Recipes Yaml to PHP Converter This is a wrapper around the symplify/config-transformer used to convert Symfony core recipes which uses .yaml c

Alexander Schranz 3 Nov 24, 2022
This library can be used, among other things, to retrieve the classes, interfaces, traits, enums, functions and constants declared in a file

marijnvanwezel/reflection-file Library that allows reflection of files. This library can be used, among other things, to retrieve the classes, interfa

Marijn van Wezel 5 Apr 17, 2022
A small marshalling library used to encode/decode data from classes

A small marshalling library used to encode/decode data from classes

Matthew Jordan 9 Sep 22, 2022
A set of PHP classes to let you manage your Dynamic Widget UI programmatically.

Dynamic Widget for Flutter A set of PHP classes to let you manage your Dynamic Widget UI programmatically. Why? Why not? Developing my application I f

Agostino Fiscale 3 Mar 22, 2022
Collection of useful PHP functions, mini-classes, and snippets for every day.

JBZoo / Utils Collection of PHP functions, mini classes and snippets for everyday developer's routine life. Install composer require jbzoo/utils Usage

JBZoo Toolbox 786 Dec 30, 2022
Directory for storing files from PHP and Logic classes

Curso Logica e PHP (C4) ✔️ Diretório para guardar os arquivos das aulas de PHP e lógica Seção 1 - Introdução Seção 2 - Lógica com VisualG e Nocões de

Bruno Henrique 1 Jan 28, 2022
A lot of scripts and packages in modern PHP demand one or more configuration classes

A lot of scripts and packages in modern PHP demand one or more configuration classes. Mostly, those are a set of properties that can be set, changed or retrieved. However, some of the configurations have a peculiar behaviour - such as boolean properties.

Carlos Artur Curvelo da Silva Matos 2 Mar 8, 2022
Snuffleupagus is a PHP 7+ and 8+ module designed to drastically raise the cost of attacks against websites, by killing entire bug classes

Snuffleupagus is a PHP 7+ and 8+ module designed to drastically raise the cost of attacks against websites, by killing entire bug classes

Julien Voisin 625 Jan 3, 2023