commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ByProjectKeyZonesHead.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
35{
40 public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null)
41 {
42 $uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/zones');
43 parent::__construct($client, 'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
44 }
45
51 public function mapFromResponse(?ResponseInterface $response, string $resultType = null)
52 {
53 if (is_null($response)) {
54 return null;
55 }
56 if (is_null($resultType)) {
57 switch ($response->getStatusCode()) {
58 case '400':
59 $resultType = ErrorResponseModel::class;
60
61 break;
62 case '401':
63 $resultType = ErrorResponseModel::class;
64
65 break;
66 case '403':
67 $resultType = ErrorResponseModel::class;
68
69 break;
70 case '500':
71 $resultType = ErrorResponseModel::class;
72
73 break;
74 case '502':
75 $resultType = ErrorResponseModel::class;
76
77 break;
78 case '503':
79 $resultType = ErrorResponseModel::class;
80
81 break;
82 default:
83 $resultType = JsonObjectModel::class;
84
85 break;
86 }
87 }
88
89 return $resultType::of($this->responseData($response));
90 }
91
98 public function execute(array $options = [], string $resultType = null)
99 {
100 try {
101 $response = $this->send($options);
102 } catch (ServerException $e) {
103 $response = $e->getResponse();
104 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
105 throw $e;
106 } catch (ClientException $e) {
107 $response = $e->getResponse();
108 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
109 throw $e;
110 }
111
112 return $this->mapFromResponse($response, $resultType);
113 }
114
121 public function executeAsync(array $options = [], string $resultType = null)
122 {
123 return $this->sendAsync($options)->then(
124 function (ResponseInterface $response) use ($resultType) {
125 return $this->mapFromResponse($response, $resultType);
126 },
127 function (RequestException $e) use ($resultType) {
128 $response = $e->getResponse();
129 if ($e instanceof ServerException) {
130 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
131 }
132 if ($e instanceof ClientException) {
133 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
134 }
135 throw $e;
136 }
137 );
138 }
139
144 public function withWhere($where): ByProjectKeyZonesHead
145 {
146 return $this->withQueryParam('where', $where);
147 }
148}
execute(array $options=[], string $resultType=null)
executeAsync(array $options=[], string $resultType=null)
mapFromResponse(?ResponseInterface $response, string $resultType=null)
__construct(string $projectKey, $body=null, array $headers=[], ClientInterface $client=null)
responseData(ResponseInterface $response)
withQueryParam(string $parameterName, $value)