Skip to content

Commit

Permalink
module 初始化逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
shirne committed Aug 11, 2024
1 parent 7e87eb6 commit c935b87
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 7 deletions.
51 changes: 51 additions & 0 deletions src/application/common/core/AppLifecycle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace app\common\core;

use think\facade\Log;

class AppLifecycle
{

public function appInit()
{
Log::record('app_init');
$dir = dirname(app()->getAppPath()) . '/extend/modules';
$modules = scandir($dir);
if (!empty($modules)) {
foreach ($modules as $module) {
if (file_exists($dir . '/' . $module . '/init.php')) {
@include_once($dir . '/' . $module . '/init.php');
}
}
}
}

public function appBegin()
{
Log::record('app_begin');
}

public function moduleInit()
{
Log::record('module_init');
}

public function actionBegin()
{
Log::record('action_begin');
}

public function viewFilter()
{
Log::record('view_filter');
}
public function logWrite()
{
//Log::record('log_write');
}
public function appEnd()
{
Log::record('app_end');
}
}
31 changes: 24 additions & 7 deletions src/application/tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,36 @@
// +----------------------------------------------------------------------

// 应用行为扩展定义文件

use app\common\core\AppLifecycle;

return [
// 应用初始化
'app_init' => [],
'app_init' => [
AppLifecycle::class
],
// 应用开始
'app_begin' => [],
'app_begin' => [
AppLifecycle::class
],
// 模块初始化
'module_init' => [],
'module_init' => [
AppLifecycle::class
],
// 操作开始执行
'action_begin' => [],
'action_begin' => [
AppLifecycle::class
],
// 视图内容过滤
'view_filter' => [],
'view_filter' => [
AppLifecycle::class
],
// 日志写入
'log_write' => [],
'log_write' => [
AppLifecycle::class
],
// 应用结束
'app_end' => [],
'app_end' => [
AppLifecycle::class
],
];
9 changes: 9 additions & 0 deletions src/extend/modules/credit/init.php
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
<?php

namespace modules\credit;

use app\common\model\PayOrderModel;
use modules\credit\model\CreditOrderModel;
use think\facade\Log;

Log::record('credit init');
PayOrderModel::register('credit', '积分订单', 'CR_', CreditOrderModel::class);

0 comments on commit c935b87

Please sign in to comment.