dualmedia/symfony-request-dto-bundle
This bundle aims to lower the burden of typechecking, casting, loading entities and related annoyances of using requests in your api.
Bundle will automatically hook into Doctrine ORM Bundle and Nelmio API Docs Bundle so no additional configuration should be needed.
#[FindOneBy], #[FindBy])#[AsRoot] for flat top-level payloads#[Bag]#[Action]s for fields, entities and more. Set custom responses via an easy to handle event.composer require dualmedia/symfony-request-dto-bundle
Then add the bundle to your config/bundles.php file like so
return [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
// other bundles ...
DualMedia\DtoRequestBundle\DtoBundle::class => ['all' => true],
];
If applicable your Doctrine entity managers will be detected automatically and used as default providers for classes to be loaded with your requests if needed.
use DualMedia\DtoRequestBundle\Dto\AbstractDto;
use DualMedia\DtoRequestBundle\Dto\Attribute\Bag;
use DualMedia\DtoRequestBundle\Metadata\Enum\BagEnum;
use Symfony\Component\HttpFoundation\File\UploadedFile;
// input:
// [
// 'name' => 'John',
// 'age' => '25',
// 'score' => '9.5',
// 'active' => '1',
// 'avatar' => <UploadedFile>,
// ]
class ProfileDto extends AbstractDto
{
public string|null $name = null;
public int|null $age = null;
public float|null $score = null;
public bool|null $active = null;
#[Bag(BagEnum::Files)]
public UploadedFile|null $avatar = null;
}
See EXAMPLES.md for enums, dates, nested DTOs, entity loading, and root-level payloads.
See CHANGES.md
How can I help you explore Laravel packages today?