PluginProbe
MONEI Payments for WooCommerce / 4.2.0
MONEI Payments for WooCommerce v4.2.0
7.3.3 7.3.2 7.3.1 7.3.0 7.2.4 7.2.3 7.2.2 7.2.0 7.2.1 7.1.3 2.1.0 3.0.0 3.1.0 3.1.1 4.0.0 4.1.0 4.1.1 4.2.0 4.2.1 5.0 5.1.0 5.1.1 5.1.2 5.2.2 5.2.3 All 87 releases
monei / includes / lib / HeaderSelector.php

HeaderSelector.php in MONEI Payments for WooCommerce 4.2.0, at includes/lib/HeaderSelector.php

111 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ApiException
4 * PHP version 5
5 *
6 * @category Class
7 * @package OpenAPI\Client
8 * @author OpenAPI Generator team
9 * @link https://openapi-generator.tech
10 */
11
12 /**
13 * MONEI API v1
14 *
15 * The MONEI API is organized around [REST](https://en.wikipedia.org/wiki/Representational_State_Transfer). Our API has predictable resource-oriented URLs, accepts JSON-encoded request bodies, returns JSON-encoded responses, and uses standard HTTP response codes, authentication, and verbs.
16 *
17 * The version of the OpenAPI document: 1.0.0
18 *
19 * Generated by: https://openapi-generator.tech
20 * OpenAPI Generator version: 4.3.1
21 */
22
23 /**
24 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
25 * https://openapi-generator.tech
26 * Do not edit the class manually.
27 */
28
29 namespace OpenAPI\Client;
30
31 use \Exception;
32
33 /**
34 * ApiException Class Doc Comment
35 *
36 * @category Class
37 * @package OpenAPI\Client
38 * @author OpenAPI Generator team
39 * @link https://openapi-generator.tech
40 */
41 class HeaderSelector
42 {
43
44 /**
45 * @param string[] $accept
46 * @param string[] $contentTypes
47 * @return array
48 */
49 public function selectHeaders($accept, $contentTypes)
50 {
51 $headers = [];
52
53 $accept = $this->selectAcceptHeader($accept);
54 if ($accept !== null) {
55 $headers['Accept'] = $accept;
56 }
57
58 $headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes);
59 return $headers;
60 }
61
62 /**
63 * @param string[] $accept
64 * @return array
65 */
66 public function selectHeadersForMultipart($accept)
67 {
68 $headers = $this->selectHeaders($accept, []);
69
70 unset($headers['Content-Type']);
71 return $headers;
72 }
73
74 /**
75 * Return the header 'Accept' based on an array of Accept provided
76 *
77 * @param string[] $accept Array of header
78 *
79 * @return string Accept (e.g. application/json)
80 */
81 private function selectAcceptHeader($accept)
82 {
83 if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) {
84 return null;
85 } elseif ($jsonAccept = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept)) {
86 return implode(',', $jsonAccept);
87 } else {
88 return implode(',', $accept);
89 }
90 }
91
92 /**
93 * Return the content type based on an array of content-type provided
94 *
95 * @param string[] $contentType Array fo content-type
96 *
97 * @return string Content-Type (e.g. application/json)
98 */
99 private function selectContentTypeHeader($contentType)
100 {
101 if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
102 return 'application/json';
103 } elseif (preg_grep("/application\/json/i", $contentType)) {
104 return 'application/json';
105 } else {
106 return implode(',', $contentType);
107 }
108 }
109 }
110
111