ge-tracker / spatie-generators
此包已被废弃,不再维护。未建议替代包。
Artisan 生成 Spatie Actions 和 DTO 的生成器
v2.0.3
2022-02-09 12:29 UTC
Requires
- php: ^8.0
- illuminate/console: ^8.0|^9.0
- illuminate/support: ^8.0|^9.0
- spatie/data-transfer-object: ^3.0
- spatie/laravel-queueable-action: ^2.5
README
此包添加了 artisan:make 命令,用于生成 Action 或 数据传输对象 (DTO)。
安装
- 安装 Spatie 生成器
composer require ge-tracker/spatie-generators
- 服务提供者将自动加载 - 安装完成!
使用
生成操作
运行以下命令将在 app/Actions 目录中生成 TestAction。
php artisan make:action TestAction
可以可选地指定 -d 或 -m 参数,以将操作生成到 Domain 或 Modules 目录。如果提供了两个参数,则领域将优先。
以下命令将在 app/Domain/Example/Actions 目录中生成 TestAction。
php artisan make:action TestAction -d Example
生成 DTO
DTO 可以像操作一样生成,并支持 -d 和 -m 参数。
php artisan make:dto TestData
DTO 也可以是 DTO 的集合,Spatie 的包将自动处理。Spatie 生成器将尝试自动决定目标数据对象的名称,以避免任何手动配置。
php artisan make:dto TestDataCollection --collection
将生成以下类
<?php namespace App\DTO; use Spatie\DataTransferObject\DataTransferObjectCollection; class TestDataCollection extends DataTransferObjectCollection { public function current(): TestData { return parent::current(); } }