PHP code example of ronghz / laravel-ddd

1. Go to this page and download the library: Download ronghz/laravel-ddd library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ronghz / laravel-ddd example snippets


Ronghz\LaravelDdd\LaravelDddServiceProvider::class,

public function __construct(Application $app, Dispatcher $events)
{
    parent::__construct($app, $events);
    $app->register(MigrationServiceProvider::class);
}
 artisan ddd-generator Article
 artisan migrate
 artisan ddd-generator Article --model=Article --table=articel_articles

├── app               // 代码目录
│ ├── Domain          // 领域代码目录
│ │ ├── Article       // 文章领域
│ │ │ ├── Commands    // 领域脚本
│ │ │ ├── Events      // 事件
│ │ │ ├── Jobs        // 
│ │ │ ├── Listeners   // 
│ │ │ ├── Models        // 模型层
│ │ │ │ ├── migrations  // 模块迁移脚本
│ │ │ │ ├── Article.php
│ │ │ ├── Repositories  // 仓库层
│ │ │ │ ├── ArticleRepository.php
│ │ │ ├── Resources     // API资源类
│ │ │ │ ├── ArticleResource.php
│ │ │ ├── Ports         // 接口层
│ │ │ │ ├── Cross       // 跨域调用接口
│ │ │ │ │ ├── ArticleCrossDomain.php
│ │ │ │ ├── Platform    // 平台管理端接口
│ │ │ │ │ ├── Controllers // 这个端的接口
│ │ │ │ │ │ ├── ArticleController.php
│ │ │ │ │ ├── Requests   // 这个端的输入参数类
│ │ │ │ │ │ ├── ArticleResource.php
│ │ │ │ │ ├── Services    // 应用服务
│ │ │ │ │ │ ├── ArticleService.php
│ │ │ │ │ ├── routes.php  // 这个端的路由配置
│ │ │ │ ├── Customer // 客户端接口
│ │ │ ├── Services   // 领域服务
│ │ │ │ ├── ArticleService.php
│ │ │ ├── Supports   // 
│ │ │ │ ├── Dtos     // 枚举变量
│ │ │ │ ├── Enums    // 枚举变量
│ │ │ │ ├── Exceptions// 领域内的异常

return [
    'router' => [
        'use_auto_router' => true, //是否使用自动映射路由
        'project_prefix' => false, //自动路由是否有项目名称前缀
        'client_version_key' => 'Release-Version', //接口版本请求头
    ],

    'generator' => [
        'ports' => ['Platform', 'Merchant', 'Customer']
    ],
];
 $this->success($data)

class ArticleController extends DddController
{
    const VERSION_RANGE = [
        'getRange' => ['1.2.3', '2.2.1']
    ];

    public function getRange()
    {
        echo 'default';
    }

    public function getRangeV1_2_3()
    {
        echo '1.2.3';
    }

    public function getRangeV2_2_1()
    {
        echo '2.2.1';
    }
}