PHP code example of yadddl / serializer

1. Go to this page and download the library: Download yadddl/serializer 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/ */

    

yadddl / serializer example snippets


class SillyDTO {
    public function __construct(
        private string $propertyOne,
        private int $propertyTwo, 
        private string $hiddenProperty 
    ) {}
    
    public function getPropertyOne(): string 
    { 
        return $this->propertyOne; 
    }
    
    public function getPropertyTwo(): int 
    { 
        return $this->propertyTwo; 
    } 
}

use Yadddl\Serializer\Factory\SerializerBaseFactory;

// Fastest way to create a basic serializer
$serializer = SerializerBaseFactory::make();

$dto = new SillyDTO('one', 2, 'hidden');

$data = $serializer->serialize($dto);


echo json_encode($data, JSON_PRETTY_PRINT);