1: <?php
2: /**
3: * ApiException
4: * PHP version 7.4
5: *
6: * @category Class
7: * @package Ally\PetStore
8: * @author OpenAPI Generator team
9: * @link https://openapi-generator.tech
10: */
11:
12: /**
13: * OpenAPI Petstore
14: *
15: * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
16: *
17: * The version of the OpenAPI document: 1.0.0
18: * Generated by: https://openapi-generator.tech
19: * OpenAPI Generator version: 6.1.0-SNAPSHOT
20: */
21:
22: /**
23: * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
24: * https://openapi-generator.tech
25: * Do not edit the class manually.
26: */
27:
28: namespace Ally\PetStore;
29:
30: use \Exception;
31:
32: /**
33: * ApiException Class Doc Comment
34: *
35: * @category Class
36: * @package Ally\PetStore
37: * @author OpenAPI Generator team
38: * @link https://openapi-generator.tech
39: */
40: class HeaderSelector
41: {
42: /**
43: * @param string[] $accept
44: * @param string[] $contentTypes
45: * @return array
46: */
47: public function selectHeaders($accept, $contentTypes)
48: {
49: $headers = [];
50:
51: $accept = $this->selectAcceptHeader($accept);
52: if ($accept !== null) {
53: $headers['Accept'] = $accept;
54: }
55:
56: $headers['Content-Type'] = $this->selectContentTypeHeader($contentTypes);
57: return $headers;
58: }
59:
60: /**
61: * @param string[] $accept
62: * @return array
63: */
64: public function selectHeadersForMultipart($accept)
65: {
66: $headers = $this->selectHeaders($accept, []);
67:
68: unset($headers['Content-Type']);
69: return $headers;
70: }
71:
72: /**
73: * Return the header 'Accept' based on an array of Accept provided
74: *
75: * @param string[] $accept Array of header
76: *
77: * @return null|string Accept (e.g. application/json)
78: */
79: private function selectAcceptHeader($accept)
80: {
81: if (count($accept) === 0 || (count($accept) === 1 && $accept[0] === '')) {
82: return null;
83: } elseif ($jsonAccept = preg_grep('~(?i)^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$~', $accept)) {
84: return implode(',', $jsonAccept);
85: } else {
86: return implode(',', $accept);
87: }
88: }
89:
90: /**
91: * Return the content type based on an array of content-type provided
92: *
93: * @param string[] $contentType Array fo content-type
94: *
95: * @return string Content-Type (e.g. application/json)
96: */
97: private function selectContentTypeHeader($contentType)
98: {
99: if (count($contentType) === 0 || (count($contentType) === 1 && $contentType[0] === '')) {
100: return 'application/json';
101: } elseif (preg_grep("/application\/json/i", $contentType)) {
102: return 'application/json';
103: } else {
104: return implode(',', $contentType);
105: }
106: }
107: }
108: