label = $label; $this->method = $method; $this->path = $path; $this->initialData = $initialData; $this->parameters = $parameters; $this->options = $options; } /** * Execute the operation and update its status according to the result * * @param ApiRequestInterface $apiService * @return ResponseInterface */ public function execute(ApiRequestInterface $apiService): ResponseInterface { $this->status = self::STATUS_PENDING; try { $response = $apiService->request($this->method, $this->path, $this->parameters, $this->options); if ($response->getStatusCode() === 200) { $this->status = self::STATUS_DONE; } else { $this->status = self::STATUS_ERROR; $this->errorMessage = 'Error ' . $response->getStatusCode() . ' : ' . $response->getContent(); throw new HttpException($response->getStatusCode(), $response->getContent()); } return $response; } catch ( HttpException | ClientExceptionInterface | TransportExceptionInterface | RedirectionExceptionInterface | ServerExceptionInterface | InvalidArgumentException $e) { $this->status = self::STATUS_ERROR; $this->errorMessage = '' . $e; throw new RuntimeException($e->getMessage()); } } /** * @return string */ public function getLabel(): string { return $this->label; } /** * @return int */ public function getStatus(): int { return $this->status; } /** * @return string */ public function getErrorMessage(): string { return $this->errorMessage; } /** * @return string */ public function getMethod(): string { return $this->method; } /** * @return string */ public function getPath(): string { return $this->path; } /** * @return array */ public function getInitialData(): array { return $this->initialData; } /** * @return array */ public function getParameters(): array { return $this->parameters; } /** * @return array */ public function getOptions(): array { return $this->options; } /** * Return an array of messages describing the change that this operation will bring * * @return array * @throws \Exception */ abstract public function getChangeLog(): array; #[Pure] public function __toString(): string { return $this->getMethod() . " " . $this->getPath(); } }