gianlu-api/laravel-design 问题修复 & 功能扩展

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

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

gianlu-api/laravel-design

Composer 安装命令:

composer require gianlu-api/laravel-design

包简介

Library to generate custom design structure in laravel

关键字:

README 文档

README

badge    badge

Laravel Design is the library that allows you to quickly generate the architecture you desire.

Requirements

  • PHP ^8.2
  • Laravel > 11

Installation

composer require gianlu-api/laravel-design

Publish Resources

php artisan vendor:publish --tag=gianlu-api:laravel-design:config

It is not mandatory to publish the config; you can create your own and specify it when running the command.

Usage

First, you will need to fill out the configuration as explained below. Once the configuration file is ready, if you are using the laravel-design configuration file run:

php artisan design

Otherwise, if you are using your own configuration file:

php artisan design --config={your_config_name}

Configurations

it is possible to generate the following types of files:

  • migrations => 'migrations'
  • classes => 'classes'
  • interfaces => 'interfaces'
  • abstract classes => 'abstract_classes'
  • models => 'models'
  • controllers => 'controllers'
    • options: type
  • requests => 'requests'
  • middlewares => 'middlewares'
  • vue components => 'vue_components'
    • options: type
  • react components => 'react_components'
  • blade components => 'blade_views'

you can choose between these types of configuration, you can also mix them if you need

  • name and path configuration
'key' => [
   [
       'name' =>'UserService',
       'path' => '/Domains/User/Domain/Services',
   ]
]
'key' => [
    'name' =>'UserService',
    'path' => '/Domains/User/Domain/Services',
]
  • path and names configuration
'key' => [
    'path' => '/Domains/User/Domain/Services',
    'names' => [
        'UserRetrieverService',
        'UserDataAccessService',
    ]
]
'key' => [
    [
        'path' => '/Domains/User/Domain/Services',
        'names' => [
            'UserRetrieverService',
            'UserDataAccessService',
        ]
    ],
    [
        'path' => '/Domains/User/Domain/Dtos',
        'names' => [
            'CreateUserData',
            'UpdateUserData',
        ]
    ]
]
  • name configuration
'key' => [
    'name' =>'/Domains/User/Domain/Services/UserService',
]
  • mixed configuration example
'classes' => [
     [
       'name' =>'UserType',
       'path' => '/Domains/User/Domain/Enums',
    ],
    [
        'path' => '/Domains/User/Domain/Services',
        'names' => [
            'UserRetrieverService',
            'UserDataAccessService',
        ]
    ],
    [
        'path' => '/Domains/User/Domain/Dtos',
        'names' => [
            'CreateUserData',
            'UpdateUserData',
        ]
    ]
    'name' =>'/Domains/User/Domain/Repositories/UserRepository',
]

Migrations configruration

'migrations' => [
    'table' => 'test_domain',
]
'migrations' => [
    'tables' => ['test_domain', 'test_domain_2']
]

Controllers configruration

it is possible for controllers to choose whether api or resource methods should be created as allowed by Laravel, by adding to the configuration array 'type' => api for api or type => resource for resources

Vue Components Configuration

it is possible for vue components to choose options between composition_api 'type' => 'compositions' and 'type' => 'options', by default a compositions component is created

Name Passed by Command

If you want, you can also pass the domain name directly to the command, so you never have to change your config structure once it’s defined like this.

[
    "migrations" => [
        "table" => "&"
    ],
    'models' => [
        'name' => '/Domains/&/Domain/Models/&',
    ],
    "classes" => [
        [
            "path" =>"/Domains/&/Domain/Services",
            "names" => ["&RetrieverService", "&DataAccessService"]
        ],
        [
            "path" =>"/Domains/&/Domain/Repositories",
            "name" => "&Repository",
        ]
    ],
    "interfaces" => [
        "path" =>"/Domains//&/DOmain/Interfaces",
        "names" => ["&ServiceRetrieverInterface", "&DataAccessServiceInterface", "&RepositoryInterface"]
    ],
    "abstract_classes" => [
        [
            "path" =>"/Domains/&/Domain/Abstracts",
            "name" => "&Abstract",
        ]
    ],
    "requests" => [
        "name" =>"../../App/Http/&/Requests/&Request",
    ],
    "middlewares" => [
        "name" =>"../../App/Http/&/Middlewares/&Middleware",
    ],
    "resources" => [
        "name" =>"../../App/Http/&/Resources/&Resource",
    ],
    "controllers" => [
        "name" =>"../../App/Http/&/Controllers/&Controller",
    ],
];

Now you can run the command like this

php artisan design {name}

Configuration Example

First, you will need to fill out the configuration file as follows.

[
    "migrations" => [
        "table" => "users"
    ],
    'models' => [
        'name' => '/Domains/User/Domain/Models/User',
    ],
    "classes" => [
        [
            "path" =>"/Domains/User/Domain/Services",
            "names" => ["UserRetrieverService", "UserDataAccessService"]
        ],
        [
            "path" =>"/Domains/User/Domain/Repositories",
            "name" => "UserRepository",
        ]
    ],
    "interfaces" => [
        "path" =>"/Domains/User/Domain/Interfaces",
        "names" => ["UserServiceRetrieverInterface", "UserDataAccessServiceInterface", "UserRepositoryInterface"]
    ],
    "abstract_classes" => [
        [
            "path" =>"/Domains/User/Domain/Abstracts",
            "name" => "UserAbstract",
        ]
    ],
    "requests" => [
        "name" =>"../../App/Http/User/Requests/UserRequest",
    ],
    "middlewares" => [
        "name" =>"../../App/Http/User/Middlewares/UserMiddleware",
    ],
    "resources" => [
        "name" =>"../../App/Http/User/Resources/UserResource",
    ],
    "controllers" => [
        "name" =>"../../App/Http/User/Controllers/UserController",
    ],
    "blade_views" => [
         "name" => "UserPage",
    ],
    "vue_components" => [
        "name" => "UserPage",
         "path" => "js/Pages",
    ],
    "react_components" => [
        "name" => "UserPage",
        "path" => "js/Pages",
    ]
];

If you want to create only specific components, simply leave the unwanted arrays empty. For example, if you need to create only a migration, model, service, and repository.

[
    "migrations" => [
        "table" => "users"
    ],
    'models' => [
        'name' => '/Domains/User/Domain/Models/User',
    ],
    "classes" => [
        [
            "path" =>"/Domains/User/Domain/Services",
            "names" => ["UserRetrieverService", "UserDataAccessService"]
        ],
        [
            "path" =>"/Domains/User/Domain/Repositories",
            "name" => "UserRepository",
        ]
    ],
    "interfaces" => [],
    "abstract_classes" => [],
    "requests" => [],
    "middlewares" => [],
    "resources" => [],
    "controllers" => [],
    "blade_views" => [],
    "vue_components" => [],
    "react_components" => []
];

Laravel Commands

Add ../../ before the path where you want to create the class; otherwise, the class will be created following Laravel's default path. For example, for the Controller: name => ../../App/Http/User/Controllers/UserController, the Controller will be created in app/App/Http/User/Controllers/UserController. On the other hand, if we use name => UserController, it will be created in app/Http/Controllers/UserController.

Other Commands

php artisan design:class {class_name} {class_path}
php artisan design:interface {interface_name} {interface_path}
php artisan design:class:abstract {abstarct_class_name} {abstract_class_path}
php artisan design:view:vue {vue_component_name} {vue_component_path} {--type=options || compositions}

Default type for Vue components is composition api.

php artisan design:view:react {react_component_name} {react_component_path}

gianlu-api/laravel-design 适用场景与选型建议

gianlu-api/laravel-design 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 213 次下载、GitHub Stars 达 3, 最近一次更新时间为 2024 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 gianlu-api/laravel-design 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-26