bigyohann/symfony-dto-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bigyohann/symfony-dto-bundle

最新稳定版本:2.0.1

Composer 安装命令:

composer require bigyohann/symfony-dto-bundle

包简介

Symfony bundle to add automatic Dto converter

README 文档

README

Motivation

  • Create and deploy a lib to packagist
  • Create a bundle for Symfony
  • Facilitate the way of handle serializing

Usage

Extends your Dto class from Bigyohann\DtoBundle\Dto\Dto, make all your properties private and add getter.

By default, I add a convert function to automatically set Dto properties to object passed as parameter.

You can annotate your property with attribute Bigyohann\DtoBundle\Attributes\ConvertProperty and if parameter shouldConvertAutomatically is set at false, property will not be mapped to object passed as parameter, but you can still access it in Dto if you want to do a specific action with this value.

if you don't want to use convert function, you can use Bigyohann\DtoBundle\Dto\DtoInterface.

Exemple

use Bigyohann\DtoBundle\Attributes\ConvertProperty;
use Bigyohann\DtoBundle\Dto\Dto;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\Type;

class UserDto extends Dto
{
    #[ConvertProperty]
    #[Type(type: 'string')]
    #[Length(min: 2, max: 20)]
    private ?string $name;    
    
    #[ConvertProperty(shouldConvertAutomatically: false)]
    #[Type(type: 'string')]
    private ?string $password;

    public function getPassword(): ?string
    {
        return $this->password;
    }

    public function getName(): ?string
    {
        return $this->name;
    }

}

Inject Dto directly in Controller functions

    public function create(UserDto $dto){
        $user = new User();
        
        $dto->transformToObject($user);
        
        // password is not automatically convert in $user, do your custom logic with $dto->getPassword()
        // Add your custom logic here
    }

统计信息

  • 总下载量: 128
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固