d5991813a6
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext - 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示 - 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法 - 增加日志记录细节,便于调试策略执行中断时的错误信息 - 优化代码注释,提升代码可读性和维护性
140 lines
3.5 KiB
PHP
140 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace app\flow\vo;
|
|
|
|
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,
|
|
];
|
|
}
|
|
}
|