commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ByProjectKeyMcpServersGet.php
1<?php
2
3declare(strict_types=1);
10
22use GuzzleHttp\ClientInterface;
23use GuzzleHttp\Exception\ClientException;
24use GuzzleHttp\Exception\RequestException;
25use GuzzleHttp\Exception\ServerException;
26use GuzzleHttp\Promise\PromiseInterface;
27
28use Psr\Http\Message\ResponseInterface;
29
39{
44 public function __construct(string $projectKey, $body = null, array $headers = [], ?ClientInterface $client = null)
45 {
46 $uri = str_replace(['{projectKey}'], [self::encodePathParam($projectKey)], '{projectKey}/mcp-servers');
47 parent::__construct($client, 'GET', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
48 }
49
55 public function mapFromResponse(?ResponseInterface $response, ?string $resultType = null)
56 {
57 if (is_null($response)) {
58 return null;
59 }
60 if (is_null($resultType)) {
61 switch ($response->getStatusCode()) {
62 case '200':
63 $resultType = McpServerPagedQueryResponseModel::class;
64
65 break;
66 case '400':
67 $resultType = ErrorResponseModel::class;
68
69 break;
70 case '401':
71 $resultType = ErrorResponseModel::class;
72
73 break;
74 case '403':
75 $resultType = ErrorResponseModel::class;
76
77 break;
78 case '500':
79 $resultType = ErrorResponseModel::class;
80
81 break;
82 case '502':
83 $resultType = ErrorResponseModel::class;
84
85 break;
86 case '503':
87 $resultType = ErrorResponseModel::class;
88
89 break;
90 default:
91 $resultType = JsonObjectModel::class;
92
93 break;
94 }
95 }
96
97 return $resultType::of($this->responseData($response));
98 }
99
106 public function execute(array $options = [], ?string $resultType = null)
107 {
108 try {
109 $response = $this->send($options);
110 } catch (ServerException $e) {
111 $response = $e->getResponse();
112 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
113 throw $e;
114 } catch (ClientException $e) {
115 $response = $e->getResponse();
116 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
117 throw $e;
118 }
119
120 return $this->mapFromResponse($response, $resultType);
121 }
122
129 public function executeAsync(array $options = [], ?string $resultType = null)
130 {
131 return $this->sendAsync($options)->then(
132 function (ResponseInterface $response) use ($resultType) {
133 return $this->mapFromResponse($response, $resultType);
134 },
135 function (RequestException $e) use ($resultType) {
136 $response = $e->getResponse();
137 if ($e instanceof ServerException) {
138 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
139 }
140 if ($e instanceof ClientException) {
141 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
142 }
143 throw $e;
144 }
145 );
146 }
147
152 public function withSort($sort): ByProjectKeyMcpServersGet
153 {
154 return $this->withQueryParam('sort', $sort);
155 }
156
161 public function withLimit($limit): ByProjectKeyMcpServersGet
162 {
163 return $this->withQueryParam('limit', $limit);
164 }
165
170 public function withOffset($offset): ByProjectKeyMcpServersGet
171 {
172 return $this->withQueryParam('offset', $offset);
173 }
174
179 public function withWithTotal($withTotal): ByProjectKeyMcpServersGet
180 {
181 return $this->withQueryParam('withTotal', $withTotal);
182 }
183}
__construct(string $projectKey, $body=null, array $headers=[], ?ClientInterface $client=null)
mapFromResponse(?ResponseInterface $response, ?string $resultType=null)
responseData(ResponseInterface $response)
withQueryParam(string $parameterName, $value)