PHP code example of micro / dto

1. Go to this page and download the library: Download micro/dto library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

micro / dto example snippets


$classGenerator = new \Micro\Library\DTO\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();

// Usage example
$user = new \User\UserTransfer();
$user
    ->setAge(19)
    ->setEmail('[email protected]');
// OR
//
$user['age'] = 19;
$user['email'] = '[email protected]';

// Validation example
$validator = new \Micro\Library\DTO\ValidatorFacadeDefault(); 
$validator->validate($user); // Validation groups by default ["Default"]   
$validator->validate($user, ['patch', 'put']); // Set validation groups ["patch", "put"]

// Serialize example
$serializer = new \Micro\Library\DTO\SerializerFacadeDefault();
$serializer->toArray($user); // Simple array
$serializer->toJson($user); // Simple Json

// Deserialize example
$serialized = $serializer->toJsonTransfer($user);
$deserialized = $serializer->fromJsonTransfer($serialized);