Files
tcpserver-flow/app/flow/vo/VoiceState.php
T
zimoyin d5991813a6 ai-refactor(flow): 调整抽象流程节点实现和依赖路径
- 修改 AbstractProcessNode 中 ProcessContext 的命名空间引用为 app\flow\context\ProcessContext
- 引入 app\flow\vo\CanHandleResult 用于节点处理结果表示
- 更新前置策略执行后对成功状态的判断,改为调用 isSuccess() 方法
- 增加日志记录细节,便于调试策略执行中断时的错误信息
- 优化代码注释,提升代码可读性和维护性
2026-03-11 00:49:02 +08:00

157 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace app\flow\vo;
use app\flow\enum\VoiceMessage;
/**
* 语音状态值对象
* 封装语音播报相关状态(不可变)
*/
readonly class VoiceState
{
public function __construct(
/** 语音播报内容 */
public string $message = '',
/** 错误消息枚举 */
public VoiceMessage $errorMessage = VoiceMessage::NONE,
/** 期望下一步提示 */
public VoiceMessage $expectedNextStep = VoiceMessage::NONE,
/** 语音模板参数 */
public array $templateParams = [],
) {}
/**
* 创建空语音状态
*/
public static function empty(): self
{
return new self();
}
/**
* 从消息创建
*/
public static function fromMessage(string|VoiceMessage $message): self
{
if ($message instanceof VoiceMessage) {
return new self(message: $message->value);
}
return new self(message: $message);
}
/**
* 从错误枚举创建
*/
public static function fromError(VoiceMessage $error): self
{
return new self(errorMessage: $error);
}
/**
* 设置语音消息
*/
public function withMessage(string|VoiceMessage $message): self
{
$msg = $message instanceof VoiceMessage ? $message->value : $message;
return new self(
message: $msg,
errorMessage: $this->errorMessage,
expectedNextStep: $this->expectedNextStep,
templateParams: $this->templateParams
);
}
/**
* 设置错误消息
*/
public function withError(VoiceMessage $error): self
{
return new self(
message: $this->message,
errorMessage: $error,
expectedNextStep: $this->expectedNextStep,
templateParams: $this->templateParams
);
}
/**
* 设置期望下一步
*/
public function withExpectedNextStep(VoiceMessage $expected): self
{
return new self(
message: $this->message,
errorMessage: $this->errorMessage,
expectedNextStep: $expected,
templateParams: $this->templateParams
);
}
/**
* 添加语音前缀
*/
public function prependMessage(string $prefix): self
{
return new self(
message: $prefix . $this->message,
errorMessage: $this->errorMessage,
expectedNextStep: $this->expectedNextStep,
templateParams: $this->templateParams
);
}
/**
* 设置模板参数
*/
public function withTemplateParams(array $params): self
{
return new self(
message: $this->message,
errorMessage: $this->errorMessage,
expectedNextStep: $this->expectedNextStep,
templateParams: $params
);
}
/**
* 获取完整语音(优先返回 message,否则返回 errorMessage
*/
public function getFullVoice(): string
{
if (!empty($this->message)) {
return $this->message;
}
return $this->errorMessage->value;
}
/**
* 是否有错误
*/
public function hasError(): bool
{
return $this->errorMessage !== VoiceMessage::NONE;
}
/**
* 是否有期望下一步提示
*/
public function hasExpectedNextStep(): bool
{
return $this->expectedNextStep !== VoiceMessage::NONE;
}
/**
* 转换为数组
*/
public function toArray(): array
{
return [
'message' => $this->message,
'errorMessage' => $this->errorMessage->name,
'expectedNextStep' => $this->expectedNextStep->name,
'templateParams' => $this->templateParams,
];
}
}