commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ByProjectKeyVariantProjectionsHead.php
1<?php
2
3declare(strict_types=1);
10
20use GuzzleHttp\ClientInterface;
21use GuzzleHttp\Exception\ClientException;
22use GuzzleHttp\Exception\RequestException;
23use GuzzleHttp\Exception\ServerException;
24use GuzzleHttp\Promise\PromiseInterface;
25
26use Psr\Http\Message\ResponseInterface;
27
37{
42 public function __construct(string $projectKey, $body = null, array $headers = [], ?ClientInterface $client = null)
43 {
44 $uri = str_replace(['{projectKey}'], [self::encodePathParam($projectKey)], '{projectKey}/variant-projections');
45 parent::__construct($client, 'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
46 }
47
53 public function mapFromResponse(?ResponseInterface $response, ?string $resultType = null)
54 {
55 if (is_null($response)) {
56 return null;
57 }
58 if (is_null($resultType)) {
59 switch ($response->getStatusCode()) {
60 case '400':
61 $resultType = ErrorResponseModel::class;
62
63 break;
64 case '401':
65 $resultType = ErrorResponseModel::class;
66
67 break;
68 case '403':
69 $resultType = ErrorResponseModel::class;
70
71 break;
72 case '500':
73 $resultType = ErrorResponseModel::class;
74
75 break;
76 case '502':
77 $resultType = ErrorResponseModel::class;
78
79 break;
80 case '503':
81 $resultType = ErrorResponseModel::class;
82
83 break;
84 default:
85 $resultType = JsonObjectModel::class;
86
87 break;
88 }
89 }
90
91 return $resultType::of($this->responseData($response));
92 }
93
100 public function execute(array $options = [], ?string $resultType = null)
101 {
102 try {
103 $response = $this->send($options);
104 } catch (ServerException $e) {
105 $response = $e->getResponse();
106 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
107 throw $e;
108 } catch (ClientException $e) {
109 $response = $e->getResponse();
110 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
111 throw $e;
112 }
113
114 return $this->mapFromResponse($response, $resultType);
115 }
116
123 public function executeAsync(array $options = [], ?string $resultType = null)
124 {
125 return $this->sendAsync($options)->then(
126 function (ResponseInterface $response) use ($resultType) {
127 return $this->mapFromResponse($response, $resultType);
128 },
129 function (RequestException $e) use ($resultType) {
130 $response = $e->getResponse();
131 if ($e instanceof ServerException) {
132 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
133 }
134 if ($e instanceof ClientException) {
135 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
136 }
137 throw $e;
138 }
139 );
140 }
141
147 {
148 return $this->withQueryParam('where', $where);
149 }
150
156 {
157 return $this->withQueryParam('staged', $staged);
158 }
159
165 {
166 return $this->withQueryParam('priceCurrency', $priceCurrency);
167 }
168
174 {
175 return $this->withQueryParam('priceCountry', $priceCountry);
176 }
177
182 public function withPriceCustomerGroup($priceCustomerGroup): ByProjectKeyVariantProjectionsHead
183 {
184 return $this->withQueryParam('priceCustomerGroup', $priceCustomerGroup);
185 }
186
192 {
193 return $this->withQueryParam('priceChannel', $priceChannel);
194 }
195
201 {
202 return $this->withQueryParam('localeProjection', $localeProjection);
203 }
204
210 {
211 return $this->withQueryParam('filter[attributes]', $filterAttributes);
212 }
213}
__construct(string $projectKey, $body=null, array $headers=[], ?ClientInterface $client=null)
responseData(ResponseInterface $response)
withQueryParam(string $parameterName, $value)