PHP code example of pfilsx / dto-param-converter-bundle

1. Go to this page and download the library: Download pfilsx/dto-param-converter-bundle 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/ */

    

pfilsx / dto-param-converter-bundle example snippets


use Pfilsx\DtoParamConverter\Annotation\Dto;
use Symfony\Component\Validator\Constraints as Assert;

/**
* @Dto() 
*/
final class SomeDto 
{
  /**
  * @Assert\NotBlank
  */
  public ?string $title = null;
  
  ...
}

public function postAction(SomeDto $someDto): Response
{
    // here dto already loaded and validated
}

/**
* @Dto(linkedEntity=SomeEntity::class) 
*/
final class SomeDto 
{
    ...
}


use Pfilsx\DtoParamConverter\Contract\DtoMapperInterface;

final class SomeDtoMapper implements DtoMapperInterface
{
    public static function getDtoClassName(): string
    {
        return SomeDto::class;
    }

    /**
     * @param object|SomeEntity   $entity
     * @param SomeDto|object $dto
     */
    public function mapToDto(object $entity, object $dto): void
    {
        // your entity to dto mapping logic
        $dto->title = $entity->getTitle();
        ...
    }
}

/**
* @DtoResolver(options={
*    DtoArgumentResolver::OPTION_SERIALIZER_CONTEXT: {},
*    DtoArgumentResolver::OPTION_VALIDATOR_GROUPS: {},
*    DtoArgumentResolver::OPTION_PRELOAD_ENTITY: true,
*    DtoArgumentResolver::OPTION_STRICT_PRELOAD_ENTITY: true,
*    DtoArgumentResolver::OPTION_ENTITY_ID_ATTRIBUTE: null,
*    DtoArgumentResolver::OPTION_ENTITY_MANAGER: null,
*    DtoArgumentResolver::OPTION_ENTITY_MAPPING: {}
*    DtoArgumentResolver::OPTION_ENTITY_EXPR: null,
*    DtoArgumentResolver::OPTION_VALIDATE: false
* })
*/
public function someAction(SomeDto $someDto): Response
{
    ...
}
 php
return [
    ...
    Pfilsx\DtoParamConverter\DtoParamConverterBundle::class => ['all' => true],
];