Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/tutor-pro/openai/Support/Header.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
/**
3
+
* Helper class for handling magic ai functionalities
4
+
*
5
+
* @package TutorPro\OpenAI
6
+
* @author Themeum <support@themeum.com>
7
+
* @link https://themeum.com
8
+
* @since 3.0.0
9
+
*/
10
+
11
+
namespace TutorPro\OpenAI\Support;
12
+
13
+
if ( ! defined( 'ABSPATH' ) ) {
14
+
exit;
15
+
}
16
+
17
+
/**
18
+
* Make the openai request header class.
19
+
*
20
+
* @since 3.0.0
21
+
*/
22
+
final class Header {
23
+
24
+
/**
25
+
* The headers
26
+
*
27
+
* @since 3.0.0
28
+
*
29
+
* @var array<string, string>
30
+
*/
31
+
private $headers = array();
32
+
33
+
/**
34
+
* The constructor method for the request headers.
35
+
*
36
+
* @since 3.0.0
37
+
*
38
+
* @param array<string, string> $headers The request headers.
39
+
*/
40
+
public function __construct( array $headers ) {
41
+
$this->headers = $headers;
42
+
}
43
+
44
+
/**
45
+
* Create the instance of the request Header.
46
+
*
47
+
* @since 3.0.0
48
+
*
49
+
* @param array<string, string> $headers The default headers.
50
+
*
51
+
* @return Header
52
+
*/
53
+
public static function create( array $headers = array() ) {
54
+
return new self( $headers );
55
+
}
56
+
57
+
/**
58
+
* With authorization request header.
59
+
*
60
+
* @since 3.0.0
61
+
*
62
+
* @param string $api_key The openai api key.
63
+
*
64
+
* @return Header
65
+
*/
66
+
public function with_authorization( string $api_key ) {
67
+
$this->headers['Authorization'] = "Bearer {$api_key}";
68
+
69
+
return $this;
70
+
}
71
+
72
+
/**
73
+
* With organization request header.
74
+
*
75
+
* @since 3.0.0
76
+
*
77
+
* @param string $organization The openai organization.
78
+
*
79
+
* @return Header
80
+
*/
81
+
public function with_organization( string $organization ) {
82
+
$this->headers['OpenAI-Organization'] = $organization;
83
+
84
+
return $this;
85
+
}
86
+
87
+
/**
88
+
* With content type header.
89
+
*
90
+
* @since 3.0.0
91
+
*
92
+
* @param string $content_type The content type value.
93
+
* @param string $prefix The content type prefix if any.
94
+
*
95
+
* @return Header
96
+
*/
97
+
public function with_content_type( string $content_type, string $prefix = '' ) {
98
+
$this->headers['Content-Type'] = $content_type . $prefix;
99
+
100
+
return $this;
101
+
}
102
+
103
+
/**
104
+
* With custom header.
105
+
*
106
+
* @since 3.0.0
107
+
*
108
+
* @param string $name The header name.
109
+
* @param string $value The header value.
110
+
*
111
+
* @return Header
112
+
*/
113
+
public function with_custom_header( string $name, string $value ) {
114
+
$this->headers[ $name ] = $value;
115
+
116
+
return $this;
117
+
}
118
+
119
+
/**
120
+
* Get the headers array.
121
+
*
122
+
* @since 3.0.0
123
+
*
124
+
* @return array<string, string>
125
+
*/
126
+
public function to_array() {
127
+
return $this->headers;
128
+
}
129
+
}
130
+