Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Latest commit

 

History

History
52 lines (37 loc) · 1.1 KB

README.md

File metadata and controls

52 lines (37 loc) · 1.1 KB

dto-bundle

DTO structures handler for symfony

NOTICE

This package has been transfered to https://github.com/vseinstrumentiru/dto-bundle and won't receive further updates.

Installation

$ composer require temirkhan/dto-bundle

Include bundle in your config

// config/bundles.php
return [
    \Temirkhan\DataObjectBundle\DataObjectBundle::class => ['all' => true],
];

Usage

<?php

use Spatie\DataTransferObject\DataTransferObject;

class RegistrationDto extends DataTransferObject
{
    /** @var string */
    public $login;
    
    /** @var string */
    public $password;

}

class RegistrationController
{
    public function __invoke(RegistrationDto $registration): JsonResponse
    {
        // Data is filled from Request::$request(or content if json) and ready for usage
        // Resolver will fail with BadRequest response if type or field mismatch.
        
        // Normally one needs validation so feel free using constraint annotations in dto
        // and validate dto here via symfony validator
    }
}