定制 kent013/artisan-command-pseudo-ca 二次开发

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

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

kent013/artisan-command-pseudo-ca

Composer 安装命令:

composer require kent013/artisan-command-pseudo-ca

包简介

An artisan command to generate usecase / request / resource classes to implement pseudo clean architecture.

README 文档

README

Artisan make command to generate usecase / request / resource classes to implement pseudo clean architecture.

This command is based on the article about pseudo clean architecture.

Pseudo / Relaxed Clean Architecture

pseudo clean architecture for laravel is a relaxed domain modelling architecture which consists with Request, Resource and Usecase. Again this architecture is proposed by mpyw. And I'm using this architecture in my several projects. so that I just need a class generator.

According to the article written by mpyw, Request is like

class StoreRequest extends FormRequest
{
    public function authorize(Gate $gate): bool
    {
        $community = $this->route()->parameter('community');
	    return $gate->authorize('store', [Post::class, $community]);
    }

    public function rules(): array
    {
        return [
            'title' => 'required|string|max:30',
            'body' => 'required|string|max:10000',
        ];
    }

    public function makePost(): Post
    {
        return new Post($this->validated());
    }
}

Resource is like

class PostResource extends JsonResource
{
    public function toArray($request): array
    {
        return [
            'title' => $this->resource->title,
            'body' => $this->resource->body,
            'created_at' => $this->resource->created_at,
            'updated_at' => $this->resource->updated_at, 
        ];
    }
}

Usecase is like

class StoreAction
{
    public function storeAfterDomainValidation(User $user, Community $community): self
    {
        $userPostsCountToday = $user
            ->posts()
            ->where('community_id', $community->id)
            ->where('created_at', '>=', Carbon::midnight())
            ->count();
        if ($userPostsCountToday >= 200) {
            throw new PostLimitExceededException('Exceeded');
        }
        
        $post->save();
        return $post;
    }
}

And controller with Request, Resource and Usecase goes like

class PostContoller
{
    public function store(StoreRequest $request, StoreAction $action): PostResource
    {
        $post = $request->makePost();

        try {
            return new PostResource($action($user, $community, $post));
        } catch (PostLimitExceededException $e) {
            throw new TooManyRequestsHttpException(null, $e->getMessage(), $e);
        }
    }
}

Installation

composer require --dev kent013/artisan-command-pseudo-ca

Generate config file

php artisan vendor:publish --tag="pseudoca"

Configuration

PSEUDOCA_USECASE_NS="\UseCases"
PSEUDOCA_REQUEST_NS="\Http\Requests"
PSEUDOCA_RESOURCE_NS="\Http\Resources"

If you want to change namespaces, please add above lines in your .env file and change values.

Generate Usecase

php artisan make:pseudoca:usecase LoginAction

will generates LoginAction class under root namespace suffixed with PSEUDOCA_USECASE_NS. Default namespace is \UseCase.

Generate Request

php artisan make:pseudoca:request LoginRequest

will generates LoginRequest class under root namespace suffixed with PSEUDOCA_REQUEST_NS. Default namespace is \Http\Requests.

Generate Resource

php artisan make:pseudoca:resource LoginResource

will generates LoginResource class under root namespace suffixed with PSEUDOCA_RESOURCE_NS. Default namespace is \Http\Resources.

Generate PseudoCA classes at once

php artisan make:pseudoca Login

will generates LoginResource, LoginRequest and LoginUsecase.

kent013/artisan-command-pseudo-ca 适用场景与选型建议

kent013/artisan-command-pseudo-ca 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 08 月 01 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「make」 「artisan」 「usecase」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kent013/artisan-command-pseudo-ca 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kent013/artisan-command-pseudo-ca 我们能提供哪些服务?
定制开发 / 二次开发

基于 kent013/artisan-command-pseudo-ca 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-01