PHP code example of owlnext-fr / dto-export

1. Go to this page and download the library: Download owlnext-fr/dto-export 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/ */

    

owlnext-fr / dto-export example snippets


# src/Dto/Output/UserOutputDTO.php


namespace App\Dto\Output;

class UserOutputDTO {
    public int $id;
    public string $name;
}

# src/Dto/Output/UserOutputDTO.php

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('app.exportable_dto')]
class UserOutputDTO {
    public int $id;
    public string $name;
}

# src/Dto/Impl/ExportableDTOInterface.php

namespace App\Dto\Impl;

use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;

#[AutoconfigureTag('app.exportable_dto')]
interface ExportableDTOInterface {}

# src/Dto/Output/UserOutputDTO.php

use App\Dto\Impl\ExportableDTOInterface;

class UserOutputDTO implements ExportableDTOInterface {
    public int $id;
    public string $name;
}

# src/Dto/Output/UserOutputDTO.php

# ...
use OwlnextFr\DtoExport\Attribute\ListOf;

class UserOutputDTO implements ExportableDTOInterface {
    #...
    
    #[ListOf(type: 'string')]
    /** @var string[] $roles list roles for this user. */
    public array $roles;
}


# src/Dto/Output/UserOutputDTO.php

# ...
use OwlnextFr\DtoExport\Attribute\ListOf;
use App\DTO\Output\SkillOutputDTO;

class UserOutputDTO implements ExportableDTOInterface {
    #...
    
    #[ListOf(type: SkillOutputDTO::class)]
    /** @var SkillOutputDTO[] $roles list skills of this user. */
    public array $skills;
}