data = $data; $this->parse(); } /** * @throws Exception */ private function parse(): void { // 验证数据 if (! $this->validate()) { throw new Exception('Invalid data'); } $this->name = $this->data['name']; $this->description = $this->data['description']; $this->homepage_url = $this->data['homepage_url']; $this->callback_url = $this->data['callback_url']; $this->fetchFunctions(); } private function validate(): bool { // all fields are required if (empty($this->data['name']) || empty($this->data['description']) || empty($this->data['homepage_url']) || empty($this->data['callback_url'])) { return false; } return true; } /** * @throws Exception */ private function fetchFunctions(): void { foreach ($this->data['functions'] as $f) { $this->toolFunctions[] = new ToolFunction($f); } } }