ge-tracker/spatie-generators

此包已被废弃,不再维护。未建议替代包。

Artisan 生成 Spatie Actions 和 DTO 的生成器

v2.0.3 2022-02-09 12:29 UTC

This package is auto-updated.

Last update: 2023-03-06 12:09:36 UTC


README

此包添加了 artisan:make 命令,用于生成 Action数据传输对象 (DTO)

安装

  1. 安装 Spatie 生成器
composer require ge-tracker/spatie-generators
  1. 服务提供者将自动加载 - 安装完成!

使用

生成操作

运行以下命令将在 app/Actions 目录中生成 TestAction

php artisan make:action TestAction

可以可选地指定 -d-m 参数,以将操作生成到 DomainModules 目录。如果提供了两个参数,则领域将优先。

以下命令将在 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();
    }
}

贡献者