Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OperationDefinitionObject.php
Go to the documentation of this file.
1 <?php
8 
13 {
14  const HTTP_CONTENT_TYPE_HEADER = 'Content-Type';
15 
21  private $name;
22 
28  private $operation;
29 
35  private $dataType;
36 
42  private $apiMethod;
43 
49  private $apiUrl;
50 
56  private $apiUri;
57 
63  private $auth;
64 
70  private $contentType;
71 
77  private $headers = [];
78 
84  private $params = [];
85 
91  private $operationMetadata = [];
92 
98  private $successRegex;
99 
105  private $returnRegex;
106 
111  private $removeBackend;
112 
130  public function __construct(
131  $name,
132  $operation,
133  $dataType,
134  $apiMethod,
135  $apiUri,
136  $auth,
137  $headers,
138  $params,
139  $metaData,
140  $contentType,
141  $removeBackend,
142  $successRegex = null,
143  $returnRegex = null
144  ) {
145  $this->name = $name;
146  $this->operation = $operation;
147  $this->dataType = $dataType;
148  $this->apiMethod = $apiMethod;
149  $this->apiUri = trim($apiUri, '/');
150  $this->auth = $auth;
151  $this->headers = $headers;
152  $this->params = $params;
153  $this->operationMetadata = $metaData;
154  $this->successRegex = $successRegex;
155  $this->returnRegex = $returnRegex;
156  $this->removeBackend = $removeBackend;
157  $this->apiUrl = null;
158 
159  if (!empty($contentType)) {
160  $this->contentType = $contentType;
161  } else {
162  $this->contentType = 'application/x-www-form-urlencoded';
163  }
164 
165  // add content type as a header
166  $this->headers[] = self::HTTP_CONTENT_TYPE_HEADER . ': ' . $this->contentType;
167  }
168 
174  public function getDataType()
175  {
176  return $this->dataType;
177  }
178 
184  public function getOperation()
185  {
186  return $this->operation;
187  }
188 
194  public function getApiMethod()
195  {
196  return $this->apiMethod;
197  }
198 
204  public function getApiUrl()
205  {
206  if (!$this->apiUrl) {
207  $this->apiUrl = $this->apiUri;
208 
209  if (array_key_exists('query', $this->params)) {
210  $this->addQueryParams();
211  }
212  }
213 
214  return $this->apiUrl;
215  }
216 
222  public function getAuth()
223  {
224  return $this->auth;
225  }
226 
232  public function getHeaders()
233  {
234  return $this->headers;
235  }
236 
242  public function removeUrlBackend()
243  {
244  return $this->removeBackend;
245  }
246 
252  public function getContentType()
253  {
254  return $this->contentType;
255  }
256 
262  public function getOperationMetadata()
263  {
264  return $this->operationMetadata;
265  }
266 
272  public function getSuccessRegex()
273  {
274  return $this->successRegex;
275  }
276 
282  public function getReturnRegex()
283  {
284  return $this->returnRegex;
285  }
286 
292  public function addQueryParams()
293  {
294  foreach ($this->params['query'] as $paramName => $paramValue) {
295  if (strpos($this->apiUrl, '?') === false) {
296  $this->apiUrl = $this->apiUrl . "?";
297  } else {
298  $this->apiUrl = $this->apiUrl . "&";
299  }
300  $this->apiUrl = $this->apiUrl . $paramName . "=" . $paramValue;
301  }
302  }
303 }
__construct( $name, $operation, $dataType, $apiMethod, $apiUri, $auth, $headers, $params, $metaData, $contentType, $removeBackend, $successRegex=null, $returnRegex=null)