webdevcave/dto 问题修复 & 功能扩展

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

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

webdevcave/dto

最新稳定版本:v1.0.1

Composer 安装命令:

composer require webdevcave/dto

包简介

Provides a foundation for data transfer objects in PHP applications. Built with support for ArrayAccess, JsonSerializable interfaces and hydration provided by our dependency injection container.

README 文档

README

Provides a foundation for data transfer objects in PHP applications. Built with support for ArrayAccess, JsonSerializable interfaces and hydration provided by our dependency injection container (webdevcave/yadic).

Requirements

Installation

Using composer:

composer require webdevcave/dto

Usage example

Extend the DataTransferObject class and define your properties. You can use the from() method to hydrate the DTO from an array.

use Webdevcave\DTO\DataTransferObject;

class UserDTO extends DataTransferObject
{
    public function __construct(
        public readonly string $name,  // Use 'readonly' for strictness.
        public readonly string $email,
    ) {}
}

// Hydrating from array
$data = ['name' => 'John Doe', 'email' => 'john@example.com'];
$user = UserDTO::from($data);

echo $user->name; // John Doe

// ArrayAccess
echo $user['email']; // john@example.com

// JSON Serialization
echo json_encode($user);

Scripts

The following scripts are available via Composer:

  • composer test: Run the tests
  • composer test-coverage: Run the tests with coverage (requires Xdebug)
  • composer check-coverage: Check the coverage (run test-coverage first)

Tests

The project uses PHPUnit for testing. You can run the tests using:

composer test

Contributing

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

License

This project is licensed under the MIT License - see the LICENSE file for details.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固