blackbird/dto-toolkit
最新稳定版本:1.0.0
Composer 安装命令:
composer require blackbird/dto-toolkit
包简介
DTO Toolkit module provides the tools for creating Data Transfer Objects (DTO) in Magento 2 while retaining Magento's key features such as plugins, preferences, etc.
README 文档
README
dto-toolkit
The Magento 2 DTO Toolkit Module provides the tools for creating Data Transfer Objects (DTO) in Magento 2 while retaining Magento's key features such as plugins, preferences, etc.
This module aims to enhance the development experience by offering a structured approach to handling data transfer within Magento applications.
Features • Installation • Usage • More modules
Features
- Easy DTO Creation: Simplifies the process of creating and managing DTOs.
- Magento Integration: Maintains full compatibility with Magento's DI system, plugins, and preferences.
- Auto Hydration: Provides a way to automatically hydrate your DTO with an array.
Installation
Requirements
- PHP >= 7.4
composer require blackbird/dto-toolkit
php bin/magento setup:upgrade
In production mode, do not forget to recompile and redeploy the static resources.
Usage
To instantiate your DTO while maintains full compatibility with Magento 2, please use the provided DTOFactory
use Blackbird\DTOToolkit\Model\Factory\DTOFactory; /** @var DTOFactory $dtoFactory **/ protected $dtoFactory; public function __construct( DTOFactory $dtoFactory ) { $this->dtoFactory = $dtoFactory; } [...] $myDtoInstance = $this->dtoFactory->create(MyDTO::class);
To automatically hydrate your DTO instance with an array
use Blackbird\DTOToolkit\Model\Factory\DTOFactory; /** @var DTOFactory $dtoFactory **/ protected $dtoFactory; public function __construct( DTOFactory $dtoFactory ) { $this->dtoFactory = $dtoFactory; } [...] myArray = [ 'key_one' => 1, 'key_two' => 2 ]; $myDtoInstance = $this->dtoFactory->create(MyDTO::class, $myArray);
Warning, if your DTO class doesn't have the properties keyOne or keyTwo, they will not be hydrated.
统计信息
- 总下载量: 146
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-05-20