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, ]; } }