[TOC]
一、修改框架核心擴展包
1. 新增指令配置項
打開文件
vendor\topthink\framework\src\think\Console.php
在 類屬性 defaultCommands 中添加以下內(nèi)容
'make:logic' => \think\console\command\make\Logic::class,
2. 創(chuàng)建邏輯層類文件模板
創(chuàng)建以下文件的一個副本
vendor\topthink\framework\src\think\console\command\make\stubs\model.stub
將副本重命名為 logic.stub, 文件內(nèi)容修改如下
<?php
declare (strict_types = 1);
namespace {%namespace%};
class {%className%}
{
}
3. 創(chuàng)建 Logic.php 文件
創(chuàng)建以下文件的一個副本
vendor\topthink\framework\src\think\console\command\make\Model.php
將副本重命名為 Logic.php, 修改內(nèi)容如下圖
vendor\topthink\framework\src\think\console\command\make\Logic.php

image
4. 執(zhí)行命令, 創(chuàng)建邏輯層類文件
執(zhí)行命令
php think make:logic common@User
生成邏輯層類文件
Logic:app\common\logic\User created successfully.
二、不用修改框架源碼 【推薦】
1. 創(chuàng)建一個自定義命令類文件 (以邏輯層類文件為例)
生成 app\command\make\Logic.php 文件
php think make:command make/Logic
2. 復(fù)制創(chuàng)建模型類的命令定義文件內(nèi)容
復(fù)制以下文件內(nèi)容, 粘貼到 app\command\make\Logic.php 文件中
vendor\topthink\framework\src\think\console\command\make\Model.php
修改內(nèi)容如下圖

image
3. 拷貝命令行生成模型類的模板
拷貝命令行生成模型類的模板, 粘貼到 app\command\make\stubs\logic.stub
vendor\topthink\framework\src\think\console\command\make\stubs\model.stub
文件內(nèi)容如下
<?php
declare (strict_types = 1);
namespace {%namespace%};
class {%className%}
{
/**
* 邏輯層靜態(tài)方法
*/
public static function demo()
{
}
}
4. 將自定義命令添加到指令配置文件 config\console.php
return [
// 指令定義
'commands' => [
'make:logic' => app\command\make\Logic::class,
],
];
5. 執(zhí)行自定義命令, 創(chuàng)建邏輯層類文件
php think make:logic api@User