data = $data; } public function getData(): mixed { return $this->data; } /** * 获取数据并转换为数组 */ public function getDataAsArray(): array { return is_array($this->data) ? $this->data : (array) $this->data; } /** * 从请求体创建实例 */ public static function fromBody(mixed $data): self { return new self($data); } /** * 检查是否有数据 */ public function hasData(): bool { return $this->data !== null; } /** * 检查数据是否为空 */ public function isEmpty(): bool { if ($this->data === null) { return true; } if (is_array($this->data)) { return empty($this->data); } if (is_object($this->data)) { return empty((array) $this->data); } return false; } }