定制 filippo-toso/laravel-domain-library 二次开发

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

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

filippo-toso/laravel-domain-library

Composer 安装命令:

composer require filippo-toso/laravel-domain-library

包简介

Build domain driven applications in Laravel

README 文档

README

I read the Laravel Beyond CRUD series and decided this is the way. But I'm a lazy coder: I really don't like to write a lot of code. So, I needed a toolkit to automate as much coding as possible. And here it is!

Requirements

  • PHP 7.2.5+
  • Laravel 7+

Laravel 11 support

I'm a little busy in this period. Laravel 11 has some critical changes that impact this package. In the next few days I'll try to find the time to make a new major release with full support for Laravel 11.

What it does?

It provides:

  • multiple console commands to create domain driven classes
  • traits and classes to speed up development

The commands prefix is domain:.

How does it work?

Let's start with a clean Laravel installation. From your favorite shell:

composer create-project laravel/laravel project

Then install the library:

cd project
composer require filippo-toso/laravel-domain-library
composer require spatie/laravel-data spatie/laravel-model-states spatie/laravel-query-builder spatie/laravel-view-models

The additional Spatie's packages are required for data transfer objects, model states, query builders and view models.

Now the fun part... First, we are going to build the domain structure:

php artisan domain:setup:structure

This command will create a new src folder that will contain 3 namespaces App, Domain and Support. It will also rewire the Laravel application to work with this new directory structure (ie. moving middlewares and providers, updating the bootstrap code, introducing a new Application class, and so on).

At this point you can start building your domain driven application. Let's create the structure for a sample domain named Invoices

php artisan domain:make:domain Invoices

Then we will prepare the administrative application part for this domain:

php artisan domain:make:application Admin\Invoices

Making domain classes

With this library you can make the following classes:

  • Models (with support for custom collections, query builders and subscribed events)
  • Model's states (using spatie/laravel-model-states)
  • Model's subscribers and model events (automagically linked to models)
  • Model's query builders (automagically loaded)
  • Model's collections (automagically loaded)
  • Data transfer objects (using spatie/data-transfer-object)
  • HTTP queries (using spatie/laravel-query-builder)
  • View models (using spatie/laravel-view-models)
  • Actions
  • Form requests

All the commands include a --force option to overwrite existing classes. Please keep in mind that with great power comes great responsibility

Customizing code generation

If you want to customize the generated code, you can publish the stubs and then edit them.

php artisan vendor:publish --tag=stubs --provider="FilippoToso\Domain\Support\ServiceProvider"

Making models

php artisan domain:make:model Invoice --domain=Invoices

Making model's states

php artisan domain:make:states --model=Invoice --domain=Invoices --states="Paid,Pending,Overdue,Cancelled"

Making model's subscribers

php artisan domain:make:subscriber --model=Invoice --domain=Invoices

Making model's events

php artisan domain:make:events --model=Invoice --domain=Invoices --events="saving,created,deleting"

Making model's subscribers and events

php artisan domain:make:subscriber --model=Invoice --domain=Invoices --events="saving,created,deleting"

Making model's collections

php artisan domain:make:collection --model=Invoice --domain=Invoices

Making model's query builders

php artisan domain:make:querybuilder --model=Invoice --domain=Invoices

Making data transfer objects

php artisan domain:make:dto Invoice --domain=Invoices --application=Admin\Invoices

Making HTTP queries

php artisan domain:make:query InvoiceIndex --domain=Invoices --application=Admin\Invoices --model=Invoice

Making view models

php artisan domain:make:viewmodel InvoiceForm --domain=Invoices --application=Admin\Invoices --model=Invoice

Making actions

php artisan domain:make:action InvoiceIndex --domain=Invoices --application=Admin\Invoices --model=Invoice

Making form requests

php artisan domain:make:request Invoice --application=Admin\Invoices

Making exceptions

php artisan domain:make:exception InvalidInvoice --domain=Invoices

Making a suite of classes

This command will create all the classes above in a single sweep:

php artisan domain:make:suite 
    --domain=Invoices 
    --application=Admin\Invoices 
    --model=Invoice 
    --states="Paid,Pending,Overdue,Cancelled"
    --events="saving,created,deleting" 
    --dtos="Invoice,CreateInvoice"
    --queries=InvoiceIndex 
    --dtos="Invoice,CreateInvoice"
    --exceptions=InvalidInvoice 
    --queries=InvoiceIndex 
    --requests=Invoice 
    --viewmodels=InvoiceForm 
    --actions="CreateInvoice,PayInvoice,CancelInvoice"

filippo-toso/laravel-domain-library 适用场景与选型建议

filippo-toso/laravel-domain-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 375 次下载、GitHub Stars 达 30, 最近一次更新时间为 2021 年 03 月 07 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 filippo-toso/laravel-domain-library 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 30
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-03-07