定制 sajadsdi/dto-tool 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

sajadsdi/dto-tool

最新稳定版本:1.0.2

Composer 安装命令:

composer require sajadsdi/dto-tool

包简介

Tools for DTO classes to easy manage

README 文档

README

DTO Tool is a PHP library that provides tools for managing Data Transfer Object (DTO) classes. It simplifies the process of working with DTOs by offering convenient methods for data manipulation and conversion.

Installation

You can install the DTO Tool library via Composer. Run the following command in your project directory:

composer require sajadsdi/dto-tool

Features

  • auto Add Dynamic Getter and Setter for Public and Private Properties (You can change Visibility)
  • Initial DTO with array
  • Export DTO to array

Requirements

  • PHP version 8.1 or higher
  • sajadsdi/php-reflection package version 1.0 or higher

Usage

  1. Create your DTO classes and define the private properties.
  2. use the DTOTrait in DTO
<?php

use Sajadsdi\DtoTool\Concerns\DTOTrait;

class MyDTOClass
{
    use DTOTrait;
    
    private string $name;
    private int $price;
    private int $total;
}
  1. You can get or set properties like below:
$dto = new MyDTOClass();
$dto->setName('pen');
$dto->setPrice(12);
$dto->setTotal(5);

//getting data
$name = $dto->getName();
$price = $dto->getPrice();
$total = $dto->getTotal();

echo "name: " . $name; // name: pen
echo "price: " . $price;// price: 12
echo "total: " . $total;// total: 5

$array = $dto->toArray();
print_r($array);// ['name' => "pen", 'price' => 12, 'total' => 5]

// you can initial data very easy
$dto->init(['name' => "ball" ,'price' => 50 ,'total' => 20]);
print_r($dto->toArray());// ['name' => "ball", 'price' => 50, 'total' => 20]
  1. you can overwrite get and set methods
<?php

use Sajadsdi\DtoTool\Concerns\DTOTrait;

class MyDTOClass
{
    use DTOTrait;
    
    private string $name;
    private int $price;
    private int $total;
    
    public function getName()
    {
        return "prefix_".$this->name;
    }
}

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.

License

This library is open-source and released under the MIT License. See the LICENSE file for more information.

Credits

DTO Tool is developed and maintained by SajaD SaeeDi.

Enjoy using DTO Tool for easy management of your DTO classes!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固