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();
...
}
}