temirkhan/dto-bundle

This package is abandoned and no longer maintained. The author suggests using the vi-tech/dto-bundle package instead.

DTO handler bundle for symfony projects

0.1.0 2020-09-03 21:14 UTC

This package is auto-updated.

Last update: 2020-09-24 07:03:09 UTC


README

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
    }
}