ai-chore(config): 调整流程配置及改进测试代码
- 将 FLOW_USE_CUSTOM_PROCESS 从 true 改为 false,禁用自定义流程 - 在 BlockTest 测试用例中改用 setBlockMode 方法设置阻断模式 - 设置统一的错误处理,将错误转为异常抛出 - 重命名 BlockTest 测试文件路径,优化测试组织结构 - 更新 IDE php include paths,调整依赖包引用顺序 - 删除无用的 tests/flow/Test.php 测试文件 - 微调 start.php、webman、windows.php 配置或代码模块
This commit is contained in:
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
|
||||
namespace app\flow\context\bean;
|
||||
|
||||
use app\flow\enum\DbOperationType;
|
||||
|
||||
/**
|
||||
* 执行结果值对象
|
||||
* 封装流程执行的结果状态(不可变)
|
||||
*/
|
||||
readonly class ExecutionResult
|
||||
{
|
||||
public function __construct(
|
||||
/** 流程执行是否成功 */
|
||||
public bool $success = true,
|
||||
/** 是否需要操作数据库 */
|
||||
public bool $needDatabaseOperation = false,
|
||||
/** 数据库操作类型列表 */
|
||||
public array $dbOperations = [],
|
||||
/** 是否需要发送WebSocket通知 */
|
||||
public bool $needWebSocketNotify = false,
|
||||
/** 跳过节点数量 */
|
||||
public int $skipNodeCount = 0,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 创建成功状态
|
||||
*/
|
||||
public static function success(): self
|
||||
{
|
||||
return new self(success: true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建失败状态
|
||||
*/
|
||||
public static function failure(): self
|
||||
{
|
||||
return new self(success: false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建需要写库的状态
|
||||
*/
|
||||
public static function withDbOperation(DbOperationType $operation): self
|
||||
{
|
||||
return new self(
|
||||
success: true,
|
||||
needDatabaseOperation: true,
|
||||
dbOperations: [$operation]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加数据库操作
|
||||
*/
|
||||
public function addDbOperation(DbOperationType $operation): self
|
||||
{
|
||||
return new self(
|
||||
success: $this->success,
|
||||
needDatabaseOperation: true,
|
||||
dbOperations: [...$this->dbOperations, $operation],
|
||||
needWebSocketNotify: $this->needWebSocketNotify,
|
||||
skipNodeCount: $this->skipNodeCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置为失败
|
||||
*/
|
||||
public function fail(): self
|
||||
{
|
||||
return new self(
|
||||
success: false,
|
||||
needDatabaseOperation: $this->needDatabaseOperation,
|
||||
dbOperations: $this->dbOperations,
|
||||
needWebSocketNotify: $this->needWebSocketNotify,
|
||||
skipNodeCount: $this->skipNodeCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置需要WebSocket通知
|
||||
*/
|
||||
public function withWebSocketNotify(bool $need = true): self
|
||||
{
|
||||
return new self(
|
||||
success: $this->success,
|
||||
needDatabaseOperation: $this->needDatabaseOperation,
|
||||
dbOperations: $this->dbOperations,
|
||||
needWebSocketNotify: $need,
|
||||
skipNodeCount: $this->skipNodeCount
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置跳过节点数
|
||||
*/
|
||||
public function withSkipNodeCount(int $count): self
|
||||
{
|
||||
return new self(
|
||||
success: $this->success,
|
||||
needDatabaseOperation: $this->needDatabaseOperation,
|
||||
dbOperations: $this->dbOperations,
|
||||
needWebSocketNotify: $this->needWebSocketNotify,
|
||||
skipNodeCount: $count
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有数据库操作
|
||||
*/
|
||||
public function hasDbOperations(): bool
|
||||
{
|
||||
return !empty($this->dbOperations);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据库操作类型名称列表
|
||||
*/
|
||||
public function getDbOperationNames(): array
|
||||
{
|
||||
return array_map(fn(DbOperationType $op) => $op->name, $this->dbOperations);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为数组
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'success' => $this->success,
|
||||
'needDatabaseOperation' => $this->needDatabaseOperation,
|
||||
'dbOperations' => $this->getDbOperationNames(),
|
||||
'needWebSocketNotify' => $this->needWebSocketNotify,
|
||||
'skipNodeCount' => $this->skipNodeCount,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user