@@ -9,266 +9,266 @@ |
||
9 | 9 | */ |
10 | 10 | final class RequestOptions |
11 | 11 | { |
12 | - /** |
|
13 | - * allow_redirects: (bool|array) Controls redirect behavior. Pass false |
|
14 | - * to disable redirects, pass true to enable redirects, pass an |
|
15 | - * associative to provide custom redirect settings. Defaults to "false". |
|
16 | - * This option only works if your handler has the RedirectMiddleware. When |
|
17 | - * passing an associative array, you can provide the following key value |
|
18 | - * pairs: |
|
19 | - * |
|
20 | - * - max: (int, default=5) maximum number of allowed redirects. |
|
21 | - * - strict: (bool, default=false) Set to true to use strict redirects |
|
22 | - * meaning redirect POST requests with POST requests vs. doing what most |
|
23 | - * browsers do which is redirect POST requests with GET requests |
|
24 | - * - referer: (bool, default=false) Set to true to enable the Referer |
|
25 | - * header. |
|
26 | - * - protocols: (array, default=['http', 'https']) Allowed redirect |
|
27 | - * protocols. |
|
28 | - * - on_redirect: (callable) PHP callable that is invoked when a redirect |
|
29 | - * is encountered. The callable is invoked with the request, the redirect |
|
30 | - * response that was received, and the effective URI. Any return value |
|
31 | - * from the on_redirect function is ignored. |
|
32 | - */ |
|
33 | - public const ALLOW_REDIRECTS = 'allow_redirects'; |
|
34 | - |
|
35 | - /** |
|
36 | - * auth: (array) Pass an array of HTTP authentication parameters to use |
|
37 | - * with the request. The array must contain the username in index [0], |
|
38 | - * the password in index [1], and you can optionally provide a built-in |
|
39 | - * authentication type in index [2]. Pass null to disable authentication |
|
40 | - * for a request. |
|
41 | - */ |
|
42 | - public const AUTH = 'auth'; |
|
43 | - |
|
44 | - /** |
|
45 | - * body: (resource|string|null|int|float|StreamInterface|callable|\Iterator) |
|
46 | - * Body to send in the request. |
|
47 | - */ |
|
48 | - public const BODY = 'body'; |
|
49 | - |
|
50 | - /** |
|
51 | - * cert: (string|array) Set to a string to specify the path to a file |
|
52 | - * containing a PEM formatted SSL client side certificate. If a password |
|
53 | - * is required, then set cert to an array containing the path to the PEM |
|
54 | - * file in the first array element followed by the certificate password |
|
55 | - * in the second array element. |
|
56 | - */ |
|
57 | - public const CERT = 'cert'; |
|
58 | - |
|
59 | - /** |
|
60 | - * cookies: (bool|OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Cookie\CookieJarInterface, default=false) |
|
61 | - * Specifies whether or not cookies are used in a request or what cookie |
|
62 | - * jar to use or what cookies to send. This option only works if your |
|
63 | - * handler has the `cookie` middleware. Valid values are `false` and |
|
64 | - * an instance of {@see \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Cookie\CookieJarInterface}. |
|
65 | - */ |
|
66 | - public const COOKIES = 'cookies'; |
|
67 | - |
|
68 | - /** |
|
69 | - * connect_timeout: (float, default=0) Float describing the number of |
|
70 | - * seconds to wait while trying to connect to a server. Use 0 to wait |
|
71 | - * 300 seconds (the default behavior). |
|
72 | - */ |
|
73 | - public const CONNECT_TIMEOUT = 'connect_timeout'; |
|
74 | - |
|
75 | - /** |
|
76 | - * crypto_method: (int) A value describing the minimum TLS protocol |
|
77 | - * version to use. |
|
78 | - * |
|
79 | - * This setting must be set to one of the |
|
80 | - * ``STREAM_CRYPTO_METHOD_TLS*_CLIENT`` constants. PHP 7.4 or higher is |
|
81 | - * required in order to use TLS 1.3, and cURL 7.34.0 or higher is required |
|
82 | - * in order to specify a crypto method, with cURL 7.52.0 or higher being |
|
83 | - * required to use TLS 1.3. |
|
84 | - */ |
|
85 | - public const CRYPTO_METHOD = 'crypto_method'; |
|
86 | - |
|
87 | - /** |
|
88 | - * debug: (bool|resource) Set to true or set to a PHP stream returned by |
|
89 | - * fopen() enable debug output with the HTTP handler used to send a |
|
90 | - * request. |
|
91 | - */ |
|
92 | - public const DEBUG = 'debug'; |
|
93 | - |
|
94 | - /** |
|
95 | - * decode_content: (bool, default=true) Specify whether or not |
|
96 | - * Content-Encoding responses (gzip, deflate, etc.) are automatically |
|
97 | - * decoded. |
|
98 | - */ |
|
99 | - public const DECODE_CONTENT = 'decode_content'; |
|
100 | - |
|
101 | - /** |
|
102 | - * delay: (int) The amount of time to delay before sending in milliseconds. |
|
103 | - */ |
|
104 | - public const DELAY = 'delay'; |
|
105 | - |
|
106 | - /** |
|
107 | - * expect: (bool|integer) Controls the behavior of the |
|
108 | - * "Expect: 100-Continue" header. |
|
109 | - * |
|
110 | - * Set to `true` to enable the "Expect: 100-Continue" header for all |
|
111 | - * requests that sends a body. Set to `false` to disable the |
|
112 | - * "Expect: 100-Continue" header for all requests. Set to a number so that |
|
113 | - * the size of the payload must be greater than the number in order to send |
|
114 | - * the Expect header. Setting to a number will send the Expect header for |
|
115 | - * all requests in which the size of the payload cannot be determined or |
|
116 | - * where the body is not rewindable. |
|
117 | - * |
|
118 | - * By default, Guzzle will add the "Expect: 100-Continue" header when the |
|
119 | - * size of the body of a request is greater than 1 MB and a request is |
|
120 | - * using HTTP/1.1. |
|
121 | - */ |
|
122 | - public const EXPECT = 'expect'; |
|
123 | - |
|
124 | - /** |
|
125 | - * form_params: (array) Associative array of form field names to values |
|
126 | - * where each value is a string or array of strings. Sets the Content-Type |
|
127 | - * header to application/x-www-form-urlencoded when no Content-Type header |
|
128 | - * is already present. |
|
129 | - */ |
|
130 | - public const FORM_PARAMS = 'form_params'; |
|
131 | - |
|
132 | - /** |
|
133 | - * headers: (array) Associative array of HTTP headers. Each value MUST be |
|
134 | - * a string or array of strings. |
|
135 | - */ |
|
136 | - public const HEADERS = 'headers'; |
|
137 | - |
|
138 | - /** |
|
139 | - * http_errors: (bool, default=true) Set to false to disable exceptions |
|
140 | - * when a non- successful HTTP response is received. By default, |
|
141 | - * exceptions will be thrown for 4xx and 5xx responses. This option only |
|
142 | - * works if your handler has the `httpErrors` middleware. |
|
143 | - */ |
|
144 | - public const HTTP_ERRORS = 'http_errors'; |
|
145 | - |
|
146 | - /** |
|
147 | - * idn: (bool|int, default=true) A combination of IDNA_* constants for |
|
148 | - * idn_to_ascii() PHP's function (see "options" parameter). Set to false to |
|
149 | - * disable IDN support completely, or to true to use the default |
|
150 | - * configuration (IDNA_DEFAULT constant). |
|
151 | - */ |
|
152 | - public const IDN_CONVERSION = 'idn_conversion'; |
|
153 | - |
|
154 | - /** |
|
155 | - * json: (mixed) Adds JSON data to a request. The provided value is JSON |
|
156 | - * encoded and a Content-Type header of application/json will be added to |
|
157 | - * the request if no Content-Type header is already present. |
|
158 | - */ |
|
159 | - public const JSON = 'json'; |
|
160 | - |
|
161 | - /** |
|
162 | - * multipart: (array) Array of associative arrays, each containing a |
|
163 | - * required "name" key mapping to the form field, name, a required |
|
164 | - * "contents" key mapping to a StreamInterface|resource|string, an |
|
165 | - * optional "headers" associative array of custom headers, and an |
|
166 | - * optional "filename" key mapping to a string to send as the filename in |
|
167 | - * the part. If no "filename" key is present, then no "filename" attribute |
|
168 | - * will be added to the part. |
|
169 | - */ |
|
170 | - public const MULTIPART = 'multipart'; |
|
171 | - |
|
172 | - /** |
|
173 | - * on_headers: (callable) A callable that is invoked when the HTTP headers |
|
174 | - * of the response have been received but the body has not yet begun to |
|
175 | - * download. |
|
176 | - */ |
|
177 | - public const ON_HEADERS = 'on_headers'; |
|
178 | - |
|
179 | - /** |
|
180 | - * on_stats: (callable) allows you to get access to transfer statistics of |
|
181 | - * a request and access the lower level transfer details of the handler |
|
182 | - * associated with your client. ``on_stats`` is a callable that is invoked |
|
183 | - * when a handler has finished sending a request. The callback is invoked |
|
184 | - * with transfer statistics about the request, the response received, or |
|
185 | - * the error encountered. Included in the data is the total amount of time |
|
186 | - * taken to send the request. |
|
187 | - */ |
|
188 | - public const ON_STATS = 'on_stats'; |
|
189 | - |
|
190 | - /** |
|
191 | - * progress: (callable) Defines a function to invoke when transfer |
|
192 | - * progress is made. The function accepts the following positional |
|
193 | - * arguments: the total number of bytes expected to be downloaded, the |
|
194 | - * number of bytes downloaded so far, the number of bytes expected to be |
|
195 | - * uploaded, the number of bytes uploaded so far. |
|
196 | - */ |
|
197 | - public const PROGRESS = 'progress'; |
|
198 | - |
|
199 | - /** |
|
200 | - * proxy: (string|array) Pass a string to specify an HTTP proxy, or an |
|
201 | - * array to specify different proxies for different protocols (where the |
|
202 | - * key is the protocol and the value is a proxy string). |
|
203 | - */ |
|
204 | - public const PROXY = 'proxy'; |
|
205 | - |
|
206 | - /** |
|
207 | - * query: (array|string) Associative array of query string values to add |
|
208 | - * to the request. This option uses PHP's http_build_query() to create |
|
209 | - * the string representation. Pass a string value if you need more |
|
210 | - * control than what this method provides |
|
211 | - */ |
|
212 | - public const QUERY = 'query'; |
|
213 | - |
|
214 | - /** |
|
215 | - * sink: (resource|string|StreamInterface) Where the data of the |
|
216 | - * response is written to. Defaults to a PHP temp stream. Providing a |
|
217 | - * string will write data to a file by the given name. |
|
218 | - */ |
|
219 | - public const SINK = 'sink'; |
|
220 | - |
|
221 | - /** |
|
222 | - * synchronous: (bool) Set to true to inform HTTP handlers that you intend |
|
223 | - * on waiting on the response. This can be useful for optimizations. Note |
|
224 | - * that a promise is still returned if you are using one of the async |
|
225 | - * client methods. |
|
226 | - */ |
|
227 | - public const SYNCHRONOUS = 'synchronous'; |
|
228 | - |
|
229 | - /** |
|
230 | - * ssl_key: (array|string) Specify the path to a file containing a private |
|
231 | - * SSL key in PEM format. If a password is required, then set to an array |
|
232 | - * containing the path to the SSL key in the first array element followed |
|
233 | - * by the password required for the certificate in the second element. |
|
234 | - */ |
|
235 | - public const SSL_KEY = 'ssl_key'; |
|
236 | - |
|
237 | - /** |
|
238 | - * stream: Set to true to attempt to stream a response rather than |
|
239 | - * download it all up-front. |
|
240 | - */ |
|
241 | - public const STREAM = 'stream'; |
|
242 | - |
|
243 | - /** |
|
244 | - * verify: (bool|string, default=true) Describes the SSL certificate |
|
245 | - * verification behavior of a request. Set to true to enable SSL |
|
246 | - * certificate verification using the system CA bundle when available |
|
247 | - * (the default). Set to false to disable certificate verification (this |
|
248 | - * is insecure!). Set to a string to provide the path to a CA bundle on |
|
249 | - * disk to enable verification using a custom certificate. |
|
250 | - */ |
|
251 | - public const VERIFY = 'verify'; |
|
252 | - |
|
253 | - /** |
|
254 | - * timeout: (float, default=0) Float describing the timeout of the |
|
255 | - * request in seconds. Use 0 to wait indefinitely (the default behavior). |
|
256 | - */ |
|
257 | - public const TIMEOUT = 'timeout'; |
|
258 | - |
|
259 | - /** |
|
260 | - * read_timeout: (float, default=default_socket_timeout ini setting) Float describing |
|
261 | - * the body read timeout, for stream requests. |
|
262 | - */ |
|
263 | - public const READ_TIMEOUT = 'read_timeout'; |
|
264 | - |
|
265 | - /** |
|
266 | - * version: (float) Specifies the HTTP protocol version to attempt to use. |
|
267 | - */ |
|
268 | - public const VERSION = 'version'; |
|
269 | - |
|
270 | - /** |
|
271 | - * force_ip_resolve: (bool) Force client to use only ipv4 or ipv6 protocol |
|
272 | - */ |
|
273 | - public const FORCE_IP_RESOLVE = 'force_ip_resolve'; |
|
12 | + /** |
|
13 | + * allow_redirects: (bool|array) Controls redirect behavior. Pass false |
|
14 | + * to disable redirects, pass true to enable redirects, pass an |
|
15 | + * associative to provide custom redirect settings. Defaults to "false". |
|
16 | + * This option only works if your handler has the RedirectMiddleware. When |
|
17 | + * passing an associative array, you can provide the following key value |
|
18 | + * pairs: |
|
19 | + * |
|
20 | + * - max: (int, default=5) maximum number of allowed redirects. |
|
21 | + * - strict: (bool, default=false) Set to true to use strict redirects |
|
22 | + * meaning redirect POST requests with POST requests vs. doing what most |
|
23 | + * browsers do which is redirect POST requests with GET requests |
|
24 | + * - referer: (bool, default=false) Set to true to enable the Referer |
|
25 | + * header. |
|
26 | + * - protocols: (array, default=['http', 'https']) Allowed redirect |
|
27 | + * protocols. |
|
28 | + * - on_redirect: (callable) PHP callable that is invoked when a redirect |
|
29 | + * is encountered. The callable is invoked with the request, the redirect |
|
30 | + * response that was received, and the effective URI. Any return value |
|
31 | + * from the on_redirect function is ignored. |
|
32 | + */ |
|
33 | + public const ALLOW_REDIRECTS = 'allow_redirects'; |
|
34 | + |
|
35 | + /** |
|
36 | + * auth: (array) Pass an array of HTTP authentication parameters to use |
|
37 | + * with the request. The array must contain the username in index [0], |
|
38 | + * the password in index [1], and you can optionally provide a built-in |
|
39 | + * authentication type in index [2]. Pass null to disable authentication |
|
40 | + * for a request. |
|
41 | + */ |
|
42 | + public const AUTH = 'auth'; |
|
43 | + |
|
44 | + /** |
|
45 | + * body: (resource|string|null|int|float|StreamInterface|callable|\Iterator) |
|
46 | + * Body to send in the request. |
|
47 | + */ |
|
48 | + public const BODY = 'body'; |
|
49 | + |
|
50 | + /** |
|
51 | + * cert: (string|array) Set to a string to specify the path to a file |
|
52 | + * containing a PEM formatted SSL client side certificate. If a password |
|
53 | + * is required, then set cert to an array containing the path to the PEM |
|
54 | + * file in the first array element followed by the certificate password |
|
55 | + * in the second array element. |
|
56 | + */ |
|
57 | + public const CERT = 'cert'; |
|
58 | + |
|
59 | + /** |
|
60 | + * cookies: (bool|OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Cookie\CookieJarInterface, default=false) |
|
61 | + * Specifies whether or not cookies are used in a request or what cookie |
|
62 | + * jar to use or what cookies to send. This option only works if your |
|
63 | + * handler has the `cookie` middleware. Valid values are `false` and |
|
64 | + * an instance of {@see \OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Cookie\CookieJarInterface}. |
|
65 | + */ |
|
66 | + public const COOKIES = 'cookies'; |
|
67 | + |
|
68 | + /** |
|
69 | + * connect_timeout: (float, default=0) Float describing the number of |
|
70 | + * seconds to wait while trying to connect to a server. Use 0 to wait |
|
71 | + * 300 seconds (the default behavior). |
|
72 | + */ |
|
73 | + public const CONNECT_TIMEOUT = 'connect_timeout'; |
|
74 | + |
|
75 | + /** |
|
76 | + * crypto_method: (int) A value describing the minimum TLS protocol |
|
77 | + * version to use. |
|
78 | + * |
|
79 | + * This setting must be set to one of the |
|
80 | + * ``STREAM_CRYPTO_METHOD_TLS*_CLIENT`` constants. PHP 7.4 or higher is |
|
81 | + * required in order to use TLS 1.3, and cURL 7.34.0 or higher is required |
|
82 | + * in order to specify a crypto method, with cURL 7.52.0 or higher being |
|
83 | + * required to use TLS 1.3. |
|
84 | + */ |
|
85 | + public const CRYPTO_METHOD = 'crypto_method'; |
|
86 | + |
|
87 | + /** |
|
88 | + * debug: (bool|resource) Set to true or set to a PHP stream returned by |
|
89 | + * fopen() enable debug output with the HTTP handler used to send a |
|
90 | + * request. |
|
91 | + */ |
|
92 | + public const DEBUG = 'debug'; |
|
93 | + |
|
94 | + /** |
|
95 | + * decode_content: (bool, default=true) Specify whether or not |
|
96 | + * Content-Encoding responses (gzip, deflate, etc.) are automatically |
|
97 | + * decoded. |
|
98 | + */ |
|
99 | + public const DECODE_CONTENT = 'decode_content'; |
|
100 | + |
|
101 | + /** |
|
102 | + * delay: (int) The amount of time to delay before sending in milliseconds. |
|
103 | + */ |
|
104 | + public const DELAY = 'delay'; |
|
105 | + |
|
106 | + /** |
|
107 | + * expect: (bool|integer) Controls the behavior of the |
|
108 | + * "Expect: 100-Continue" header. |
|
109 | + * |
|
110 | + * Set to `true` to enable the "Expect: 100-Continue" header for all |
|
111 | + * requests that sends a body. Set to `false` to disable the |
|
112 | + * "Expect: 100-Continue" header for all requests. Set to a number so that |
|
113 | + * the size of the payload must be greater than the number in order to send |
|
114 | + * the Expect header. Setting to a number will send the Expect header for |
|
115 | + * all requests in which the size of the payload cannot be determined or |
|
116 | + * where the body is not rewindable. |
|
117 | + * |
|
118 | + * By default, Guzzle will add the "Expect: 100-Continue" header when the |
|
119 | + * size of the body of a request is greater than 1 MB and a request is |
|
120 | + * using HTTP/1.1. |
|
121 | + */ |
|
122 | + public const EXPECT = 'expect'; |
|
123 | + |
|
124 | + /** |
|
125 | + * form_params: (array) Associative array of form field names to values |
|
126 | + * where each value is a string or array of strings. Sets the Content-Type |
|
127 | + * header to application/x-www-form-urlencoded when no Content-Type header |
|
128 | + * is already present. |
|
129 | + */ |
|
130 | + public const FORM_PARAMS = 'form_params'; |
|
131 | + |
|
132 | + /** |
|
133 | + * headers: (array) Associative array of HTTP headers. Each value MUST be |
|
134 | + * a string or array of strings. |
|
135 | + */ |
|
136 | + public const HEADERS = 'headers'; |
|
137 | + |
|
138 | + /** |
|
139 | + * http_errors: (bool, default=true) Set to false to disable exceptions |
|
140 | + * when a non- successful HTTP response is received. By default, |
|
141 | + * exceptions will be thrown for 4xx and 5xx responses. This option only |
|
142 | + * works if your handler has the `httpErrors` middleware. |
|
143 | + */ |
|
144 | + public const HTTP_ERRORS = 'http_errors'; |
|
145 | + |
|
146 | + /** |
|
147 | + * idn: (bool|int, default=true) A combination of IDNA_* constants for |
|
148 | + * idn_to_ascii() PHP's function (see "options" parameter). Set to false to |
|
149 | + * disable IDN support completely, or to true to use the default |
|
150 | + * configuration (IDNA_DEFAULT constant). |
|
151 | + */ |
|
152 | + public const IDN_CONVERSION = 'idn_conversion'; |
|
153 | + |
|
154 | + /** |
|
155 | + * json: (mixed) Adds JSON data to a request. The provided value is JSON |
|
156 | + * encoded and a Content-Type header of application/json will be added to |
|
157 | + * the request if no Content-Type header is already present. |
|
158 | + */ |
|
159 | + public const JSON = 'json'; |
|
160 | + |
|
161 | + /** |
|
162 | + * multipart: (array) Array of associative arrays, each containing a |
|
163 | + * required "name" key mapping to the form field, name, a required |
|
164 | + * "contents" key mapping to a StreamInterface|resource|string, an |
|
165 | + * optional "headers" associative array of custom headers, and an |
|
166 | + * optional "filename" key mapping to a string to send as the filename in |
|
167 | + * the part. If no "filename" key is present, then no "filename" attribute |
|
168 | + * will be added to the part. |
|
169 | + */ |
|
170 | + public const MULTIPART = 'multipart'; |
|
171 | + |
|
172 | + /** |
|
173 | + * on_headers: (callable) A callable that is invoked when the HTTP headers |
|
174 | + * of the response have been received but the body has not yet begun to |
|
175 | + * download. |
|
176 | + */ |
|
177 | + public const ON_HEADERS = 'on_headers'; |
|
178 | + |
|
179 | + /** |
|
180 | + * on_stats: (callable) allows you to get access to transfer statistics of |
|
181 | + * a request and access the lower level transfer details of the handler |
|
182 | + * associated with your client. ``on_stats`` is a callable that is invoked |
|
183 | + * when a handler has finished sending a request. The callback is invoked |
|
184 | + * with transfer statistics about the request, the response received, or |
|
185 | + * the error encountered. Included in the data is the total amount of time |
|
186 | + * taken to send the request. |
|
187 | + */ |
|
188 | + public const ON_STATS = 'on_stats'; |
|
189 | + |
|
190 | + /** |
|
191 | + * progress: (callable) Defines a function to invoke when transfer |
|
192 | + * progress is made. The function accepts the following positional |
|
193 | + * arguments: the total number of bytes expected to be downloaded, the |
|
194 | + * number of bytes downloaded so far, the number of bytes expected to be |
|
195 | + * uploaded, the number of bytes uploaded so far. |
|
196 | + */ |
|
197 | + public const PROGRESS = 'progress'; |
|
198 | + |
|
199 | + /** |
|
200 | + * proxy: (string|array) Pass a string to specify an HTTP proxy, or an |
|
201 | + * array to specify different proxies for different protocols (where the |
|
202 | + * key is the protocol and the value is a proxy string). |
|
203 | + */ |
|
204 | + public const PROXY = 'proxy'; |
|
205 | + |
|
206 | + /** |
|
207 | + * query: (array|string) Associative array of query string values to add |
|
208 | + * to the request. This option uses PHP's http_build_query() to create |
|
209 | + * the string representation. Pass a string value if you need more |
|
210 | + * control than what this method provides |
|
211 | + */ |
|
212 | + public const QUERY = 'query'; |
|
213 | + |
|
214 | + /** |
|
215 | + * sink: (resource|string|StreamInterface) Where the data of the |
|
216 | + * response is written to. Defaults to a PHP temp stream. Providing a |
|
217 | + * string will write data to a file by the given name. |
|
218 | + */ |
|
219 | + public const SINK = 'sink'; |
|
220 | + |
|
221 | + /** |
|
222 | + * synchronous: (bool) Set to true to inform HTTP handlers that you intend |
|
223 | + * on waiting on the response. This can be useful for optimizations. Note |
|
224 | + * that a promise is still returned if you are using one of the async |
|
225 | + * client methods. |
|
226 | + */ |
|
227 | + public const SYNCHRONOUS = 'synchronous'; |
|
228 | + |
|
229 | + /** |
|
230 | + * ssl_key: (array|string) Specify the path to a file containing a private |
|
231 | + * SSL key in PEM format. If a password is required, then set to an array |
|
232 | + * containing the path to the SSL key in the first array element followed |
|
233 | + * by the password required for the certificate in the second element. |
|
234 | + */ |
|
235 | + public const SSL_KEY = 'ssl_key'; |
|
236 | + |
|
237 | + /** |
|
238 | + * stream: Set to true to attempt to stream a response rather than |
|
239 | + * download it all up-front. |
|
240 | + */ |
|
241 | + public const STREAM = 'stream'; |
|
242 | + |
|
243 | + /** |
|
244 | + * verify: (bool|string, default=true) Describes the SSL certificate |
|
245 | + * verification behavior of a request. Set to true to enable SSL |
|
246 | + * certificate verification using the system CA bundle when available |
|
247 | + * (the default). Set to false to disable certificate verification (this |
|
248 | + * is insecure!). Set to a string to provide the path to a CA bundle on |
|
249 | + * disk to enable verification using a custom certificate. |
|
250 | + */ |
|
251 | + public const VERIFY = 'verify'; |
|
252 | + |
|
253 | + /** |
|
254 | + * timeout: (float, default=0) Float describing the timeout of the |
|
255 | + * request in seconds. Use 0 to wait indefinitely (the default behavior). |
|
256 | + */ |
|
257 | + public const TIMEOUT = 'timeout'; |
|
258 | + |
|
259 | + /** |
|
260 | + * read_timeout: (float, default=default_socket_timeout ini setting) Float describing |
|
261 | + * the body read timeout, for stream requests. |
|
262 | + */ |
|
263 | + public const READ_TIMEOUT = 'read_timeout'; |
|
264 | + |
|
265 | + /** |
|
266 | + * version: (float) Specifies the HTTP protocol version to attempt to use. |
|
267 | + */ |
|
268 | + public const VERSION = 'version'; |
|
269 | + |
|
270 | + /** |
|
271 | + * force_ip_resolve: (bool) Force client to use only ipv4 or ipv6 protocol |
|
272 | + */ |
|
273 | + public const FORCE_IP_RESOLVE = 'force_ip_resolve'; |
|
274 | 274 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | * |
8 | 8 | * @see https://docs.guzzlephp.org/en/latest/request-options.html |
9 | 9 | */ |
10 | -final class RequestOptions |
|
11 | -{ |
|
10 | +final class RequestOptions { |
|
12 | 11 | /** |
13 | 12 | * allow_redirects: (bool|array) Controls redirect behavior. Pass false |
14 | 13 | * to disable redirects, pass true to enable redirects, pass an |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | */ |
16 | 16 | function describe_type($input): string |
17 | 17 | { |
18 | - return Utils::describeType($input); |
|
18 | + return Utils::describeType($input); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | function headers_from_lines(iterable $lines): array |
30 | 30 | { |
31 | - return Utils::headersFromLines($lines); |
|
31 | + return Utils::headersFromLines($lines); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | /** |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | function debug_resource($value = null) |
44 | 44 | { |
45 | - return Utils::debugResource($value); |
|
45 | + return Utils::debugResource($value); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | function choose_handler(): callable |
60 | 60 | { |
61 | - return Utils::chooseHandler(); |
|
61 | + return Utils::chooseHandler(); |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | */ |
69 | 69 | function default_user_agent(): string |
70 | 70 | { |
71 | - return Utils::defaultUserAgent(); |
|
71 | + return Utils::defaultUserAgent(); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function default_ca_bundle(): string |
90 | 90 | { |
91 | - return Utils::defaultCaBundle(); |
|
91 | + return Utils::defaultCaBundle(); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | function normalize_header_keys(array $headers): array |
101 | 101 | { |
102 | - return Utils::normalizeHeaderKeys($headers); |
|
102 | + return Utils::normalizeHeaderKeys($headers); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | function is_host_in_noproxy(string $host, array $noProxyArray): bool |
127 | 127 | { |
128 | - return Utils::isHostInNoProxy($host, $noProxyArray); |
|
128 | + return Utils::isHostInNoProxy($host, $noProxyArray); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | /** |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | function json_decode(string $json, bool $assoc = false, int $depth = 512, int $options = 0) |
148 | 148 | { |
149 | - return Utils::jsonDecode($json, $assoc, $depth, $options); |
|
149 | + return Utils::jsonDecode($json, $assoc, $depth, $options); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -163,5 +163,5 @@ discard block |
||
163 | 163 | */ |
164 | 164 | function json_encode($value, int $options = 0, int $depth = 512): string |
165 | 165 | { |
166 | - return Utils::jsonEncode($value, $options, $depth); |
|
166 | + return Utils::jsonEncode($value, $options, $depth); |
|
167 | 167 | } |
@@ -7,482 +7,482 @@ |
||
7 | 7 | */ |
8 | 8 | class SetCookie |
9 | 9 | { |
10 | - /** |
|
11 | - * @var array |
|
12 | - */ |
|
13 | - private static $defaults = [ |
|
14 | - 'Name' => null, |
|
15 | - 'Value' => null, |
|
16 | - 'Domain' => null, |
|
17 | - 'Path' => '/', |
|
18 | - 'Max-Age' => null, |
|
19 | - 'Expires' => null, |
|
20 | - 'Secure' => false, |
|
21 | - 'Discard' => false, |
|
22 | - 'HttpOnly' => false, |
|
23 | - ]; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var array Cookie data |
|
27 | - */ |
|
28 | - private $data; |
|
29 | - |
|
30 | - /** |
|
31 | - * Create a new SetCookie object from a string. |
|
32 | - * |
|
33 | - * @param string $cookie Set-Cookie header string |
|
34 | - */ |
|
35 | - public static function fromString(string $cookie): self |
|
36 | - { |
|
37 | - // Create the default return array |
|
38 | - $data = self::$defaults; |
|
39 | - // Explode the cookie string using a series of semicolons |
|
40 | - $pieces = \array_filter(\array_map('trim', \explode(';', $cookie))); |
|
41 | - // The name of the cookie (first kvp) must exist and include an equal sign. |
|
42 | - if (!isset($pieces[0]) || \strpos($pieces[0], '=') === false) { |
|
43 | - return new self($data); |
|
44 | - } |
|
45 | - |
|
46 | - // Add the cookie pieces into the parsed data array |
|
47 | - foreach ($pieces as $part) { |
|
48 | - $cookieParts = \explode('=', $part, 2); |
|
49 | - $key = \trim($cookieParts[0]); |
|
50 | - $value = isset($cookieParts[1]) |
|
51 | - ? \trim($cookieParts[1], " \n\r\t\0\x0B") |
|
52 | - : true; |
|
53 | - |
|
54 | - // Only check for non-cookies when cookies have been found |
|
55 | - if (!isset($data['Name'])) { |
|
56 | - $data['Name'] = $key; |
|
57 | - $data['Value'] = $value; |
|
58 | - } else { |
|
59 | - foreach (\array_keys(self::$defaults) as $search) { |
|
60 | - if (!\strcasecmp($search, $key)) { |
|
61 | - if ($search === 'Max-Age') { |
|
62 | - if (is_numeric($value)) { |
|
63 | - $data[$search] = (int) $value; |
|
64 | - } |
|
65 | - } else { |
|
66 | - $data[$search] = $value; |
|
67 | - } |
|
68 | - continue 2; |
|
69 | - } |
|
70 | - } |
|
71 | - $data[$key] = $value; |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - return new self($data); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @param array $data Array of cookie data provided by a Cookie parser |
|
80 | - */ |
|
81 | - public function __construct(array $data = []) |
|
82 | - { |
|
83 | - $this->data = self::$defaults; |
|
84 | - |
|
85 | - if (isset($data['Name'])) { |
|
86 | - $this->setName($data['Name']); |
|
87 | - } |
|
88 | - |
|
89 | - if (isset($data['Value'])) { |
|
90 | - $this->setValue($data['Value']); |
|
91 | - } |
|
92 | - |
|
93 | - if (isset($data['Domain'])) { |
|
94 | - $this->setDomain($data['Domain']); |
|
95 | - } |
|
96 | - |
|
97 | - if (isset($data['Path'])) { |
|
98 | - $this->setPath($data['Path']); |
|
99 | - } |
|
100 | - |
|
101 | - if (isset($data['Max-Age'])) { |
|
102 | - $this->setMaxAge($data['Max-Age']); |
|
103 | - } |
|
104 | - |
|
105 | - if (isset($data['Expires'])) { |
|
106 | - $this->setExpires($data['Expires']); |
|
107 | - } |
|
108 | - |
|
109 | - if (isset($data['Secure'])) { |
|
110 | - $this->setSecure($data['Secure']); |
|
111 | - } |
|
112 | - |
|
113 | - if (isset($data['Discard'])) { |
|
114 | - $this->setDiscard($data['Discard']); |
|
115 | - } |
|
116 | - |
|
117 | - if (isset($data['HttpOnly'])) { |
|
118 | - $this->setHttpOnly($data['HttpOnly']); |
|
119 | - } |
|
120 | - |
|
121 | - // Set the remaining values that don't have extra validation logic |
|
122 | - foreach (array_diff(array_keys($data), array_keys(self::$defaults)) as $key) { |
|
123 | - $this->data[$key] = $data[$key]; |
|
124 | - } |
|
125 | - |
|
126 | - // Extract the Expires value and turn it into a UNIX timestamp if needed |
|
127 | - if (!$this->getExpires() && $this->getMaxAge()) { |
|
128 | - // Calculate the Expires date |
|
129 | - $this->setExpires(\time() + $this->getMaxAge()); |
|
130 | - } elseif (null !== ($expires = $this->getExpires()) && !\is_numeric($expires)) { |
|
131 | - $this->setExpires($expires); |
|
132 | - } |
|
133 | - } |
|
134 | - |
|
135 | - public function __toString() |
|
136 | - { |
|
137 | - $str = $this->data['Name'].'='.($this->data['Value'] ?? '').'; '; |
|
138 | - foreach ($this->data as $k => $v) { |
|
139 | - if ($k !== 'Name' && $k !== 'Value' && $v !== null && $v !== false) { |
|
140 | - if ($k === 'Expires') { |
|
141 | - $str .= 'Expires='.\gmdate('D, d M Y H:i:s \G\M\T', $v).'; '; |
|
142 | - } else { |
|
143 | - $str .= ($v === true ? $k : "{$k}={$v}").'; '; |
|
144 | - } |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return \rtrim($str, '; '); |
|
149 | - } |
|
150 | - |
|
151 | - public function toArray(): array |
|
152 | - { |
|
153 | - return $this->data; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * Get the cookie name. |
|
158 | - * |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function getName() |
|
162 | - { |
|
163 | - return $this->data['Name']; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Set the cookie name. |
|
168 | - * |
|
169 | - * @param string $name Cookie name |
|
170 | - */ |
|
171 | - public function setName($name): void |
|
172 | - { |
|
173 | - if (!is_string($name)) { |
|
174 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
175 | - } |
|
176 | - |
|
177 | - $this->data['Name'] = (string) $name; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Get the cookie value. |
|
182 | - * |
|
183 | - * @return string|null |
|
184 | - */ |
|
185 | - public function getValue() |
|
186 | - { |
|
187 | - return $this->data['Value']; |
|
188 | - } |
|
189 | - |
|
190 | - /** |
|
191 | - * Set the cookie value. |
|
192 | - * |
|
193 | - * @param string $value Cookie value |
|
194 | - */ |
|
195 | - public function setValue($value): void |
|
196 | - { |
|
197 | - if (!is_string($value)) { |
|
198 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
199 | - } |
|
200 | - |
|
201 | - $this->data['Value'] = (string) $value; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get the domain. |
|
206 | - * |
|
207 | - * @return string|null |
|
208 | - */ |
|
209 | - public function getDomain() |
|
210 | - { |
|
211 | - return $this->data['Domain']; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Set the domain of the cookie. |
|
216 | - * |
|
217 | - * @param string|null $domain |
|
218 | - */ |
|
219 | - public function setDomain($domain): void |
|
220 | - { |
|
221 | - if (!is_string($domain) && null !== $domain) { |
|
222 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
223 | - } |
|
224 | - |
|
225 | - $this->data['Domain'] = null === $domain ? null : (string) $domain; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Get the path. |
|
230 | - * |
|
231 | - * @return string |
|
232 | - */ |
|
233 | - public function getPath() |
|
234 | - { |
|
235 | - return $this->data['Path']; |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Set the path of the cookie. |
|
240 | - * |
|
241 | - * @param string $path Path of the cookie |
|
242 | - */ |
|
243 | - public function setPath($path): void |
|
244 | - { |
|
245 | - if (!is_string($path)) { |
|
246 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
247 | - } |
|
248 | - |
|
249 | - $this->data['Path'] = (string) $path; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Maximum lifetime of the cookie in seconds. |
|
254 | - * |
|
255 | - * @return int|null |
|
256 | - */ |
|
257 | - public function getMaxAge() |
|
258 | - { |
|
259 | - return null === $this->data['Max-Age'] ? null : (int) $this->data['Max-Age']; |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Set the max-age of the cookie. |
|
264 | - * |
|
265 | - * @param int|null $maxAge Max age of the cookie in seconds |
|
266 | - */ |
|
267 | - public function setMaxAge($maxAge): void |
|
268 | - { |
|
269 | - if (!is_int($maxAge) && null !== $maxAge) { |
|
270 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
271 | - } |
|
272 | - |
|
273 | - $this->data['Max-Age'] = $maxAge === null ? null : (int) $maxAge; |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * The UNIX timestamp when the cookie Expires. |
|
278 | - * |
|
279 | - * @return string|int|null |
|
280 | - */ |
|
281 | - public function getExpires() |
|
282 | - { |
|
283 | - return $this->data['Expires']; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Set the unix timestamp for which the cookie will expire. |
|
288 | - * |
|
289 | - * @param int|string|null $timestamp Unix timestamp or any English textual datetime description. |
|
290 | - */ |
|
291 | - public function setExpires($timestamp): void |
|
292 | - { |
|
293 | - if (!is_int($timestamp) && !is_string($timestamp) && null !== $timestamp) { |
|
294 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int, string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
295 | - } |
|
296 | - |
|
297 | - $this->data['Expires'] = null === $timestamp ? null : (\is_numeric($timestamp) ? (int) $timestamp : \strtotime((string) $timestamp)); |
|
298 | - } |
|
299 | - |
|
300 | - /** |
|
301 | - * Get whether or not this is a secure cookie. |
|
302 | - * |
|
303 | - * @return bool |
|
304 | - */ |
|
305 | - public function getSecure() |
|
306 | - { |
|
307 | - return $this->data['Secure']; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Set whether or not the cookie is secure. |
|
312 | - * |
|
313 | - * @param bool $secure Set to true or false if secure |
|
314 | - */ |
|
315 | - public function setSecure($secure): void |
|
316 | - { |
|
317 | - if (!is_bool($secure)) { |
|
318 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
319 | - } |
|
320 | - |
|
321 | - $this->data['Secure'] = (bool) $secure; |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * Get whether or not this is a session cookie. |
|
326 | - * |
|
327 | - * @return bool|null |
|
328 | - */ |
|
329 | - public function getDiscard() |
|
330 | - { |
|
331 | - return $this->data['Discard']; |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Set whether or not this is a session cookie. |
|
336 | - * |
|
337 | - * @param bool $discard Set to true or false if this is a session cookie |
|
338 | - */ |
|
339 | - public function setDiscard($discard): void |
|
340 | - { |
|
341 | - if (!is_bool($discard)) { |
|
342 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
343 | - } |
|
344 | - |
|
345 | - $this->data['Discard'] = (bool) $discard; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Get whether or not this is an HTTP only cookie. |
|
350 | - * |
|
351 | - * @return bool |
|
352 | - */ |
|
353 | - public function getHttpOnly() |
|
354 | - { |
|
355 | - return $this->data['HttpOnly']; |
|
356 | - } |
|
357 | - |
|
358 | - /** |
|
359 | - * Set whether or not this is an HTTP only cookie. |
|
360 | - * |
|
361 | - * @param bool $httpOnly Set to true or false if this is HTTP only |
|
362 | - */ |
|
363 | - public function setHttpOnly($httpOnly): void |
|
364 | - { |
|
365 | - if (!is_bool($httpOnly)) { |
|
366 | - trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
367 | - } |
|
368 | - |
|
369 | - $this->data['HttpOnly'] = (bool) $httpOnly; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Check if the cookie matches a path value. |
|
374 | - * |
|
375 | - * A request-path path-matches a given cookie-path if at least one of |
|
376 | - * the following conditions holds: |
|
377 | - * |
|
378 | - * - The cookie-path and the request-path are identical. |
|
379 | - * - The cookie-path is a prefix of the request-path, and the last |
|
380 | - * character of the cookie-path is %x2F ("/"). |
|
381 | - * - The cookie-path is a prefix of the request-path, and the first |
|
382 | - * character of the request-path that is not included in the cookie- |
|
383 | - * path is a %x2F ("/") character. |
|
384 | - * |
|
385 | - * @param string $requestPath Path to check against |
|
386 | - */ |
|
387 | - public function matchesPath(string $requestPath): bool |
|
388 | - { |
|
389 | - $cookiePath = $this->getPath(); |
|
390 | - |
|
391 | - // Match on exact matches or when path is the default empty "/" |
|
392 | - if ($cookiePath === '/' || $cookiePath == $requestPath) { |
|
393 | - return true; |
|
394 | - } |
|
395 | - |
|
396 | - // Ensure that the cookie-path is a prefix of the request path. |
|
397 | - if (0 !== \strpos($requestPath, $cookiePath)) { |
|
398 | - return false; |
|
399 | - } |
|
400 | - |
|
401 | - // Match if the last character of the cookie-path is "/" |
|
402 | - if (\substr($cookiePath, -1, 1) === '/') { |
|
403 | - return true; |
|
404 | - } |
|
405 | - |
|
406 | - // Match if the first character not included in cookie path is "/" |
|
407 | - return \substr($requestPath, \strlen($cookiePath), 1) === '/'; |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Check if the cookie matches a domain value. |
|
412 | - * |
|
413 | - * @param string $domain Domain to check against |
|
414 | - */ |
|
415 | - public function matchesDomain(string $domain): bool |
|
416 | - { |
|
417 | - $cookieDomain = $this->getDomain(); |
|
418 | - if (null === $cookieDomain) { |
|
419 | - return true; |
|
420 | - } |
|
421 | - |
|
422 | - // Remove the leading '.' as per spec in RFC 6265. |
|
423 | - // https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3 |
|
424 | - $cookieDomain = \ltrim(\strtolower($cookieDomain), '.'); |
|
425 | - |
|
426 | - $domain = \strtolower($domain); |
|
427 | - |
|
428 | - // Domain not set or exact match. |
|
429 | - if ('' === $cookieDomain || $domain === $cookieDomain) { |
|
430 | - return true; |
|
431 | - } |
|
432 | - |
|
433 | - // Matching the subdomain according to RFC 6265. |
|
434 | - // https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3 |
|
435 | - if (\filter_var($domain, \FILTER_VALIDATE_IP)) { |
|
436 | - return false; |
|
437 | - } |
|
438 | - |
|
439 | - return (bool) \preg_match('/\.'.\preg_quote($cookieDomain, '/').'$/', $domain); |
|
440 | - } |
|
441 | - |
|
442 | - /** |
|
443 | - * Check if the cookie is expired. |
|
444 | - */ |
|
445 | - public function isExpired(): bool |
|
446 | - { |
|
447 | - return $this->getExpires() !== null && \time() > $this->getExpires(); |
|
448 | - } |
|
449 | - |
|
450 | - /** |
|
451 | - * Check if the cookie is valid according to RFC 6265. |
|
452 | - * |
|
453 | - * @return bool|string Returns true if valid or an error message if invalid |
|
454 | - */ |
|
455 | - public function validate() |
|
456 | - { |
|
457 | - $name = $this->getName(); |
|
458 | - if ($name === '') { |
|
459 | - return 'The cookie name must not be empty'; |
|
460 | - } |
|
461 | - |
|
462 | - // Check if any of the invalid characters are present in the cookie name |
|
463 | - if (\preg_match( |
|
464 | - '/[\x00-\x20\x22\x28-\x29\x2c\x2f\x3a-\x40\x5c\x7b\x7d\x7f]/', |
|
465 | - $name |
|
466 | - )) { |
|
467 | - return 'Cookie name must not contain invalid characters: ASCII ' |
|
468 | - .'Control characters (0-31;127), space, tab and the ' |
|
469 | - .'following characters: ()<>@,;:\"/?={}'; |
|
470 | - } |
|
471 | - |
|
472 | - // Value must not be null. 0 and empty string are valid. Empty strings |
|
473 | - // are technically against RFC 6265, but known to happen in the wild. |
|
474 | - $value = $this->getValue(); |
|
475 | - if ($value === null) { |
|
476 | - return 'The cookie value must not be empty'; |
|
477 | - } |
|
478 | - |
|
479 | - // Domains must not be empty, but can be 0. "0" is not a valid internet |
|
480 | - // domain, but may be used as server name in a private network. |
|
481 | - $domain = $this->getDomain(); |
|
482 | - if ($domain === null || $domain === '') { |
|
483 | - return 'The cookie domain must not be empty'; |
|
484 | - } |
|
485 | - |
|
486 | - return true; |
|
487 | - } |
|
10 | + /** |
|
11 | + * @var array |
|
12 | + */ |
|
13 | + private static $defaults = [ |
|
14 | + 'Name' => null, |
|
15 | + 'Value' => null, |
|
16 | + 'Domain' => null, |
|
17 | + 'Path' => '/', |
|
18 | + 'Max-Age' => null, |
|
19 | + 'Expires' => null, |
|
20 | + 'Secure' => false, |
|
21 | + 'Discard' => false, |
|
22 | + 'HttpOnly' => false, |
|
23 | + ]; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var array Cookie data |
|
27 | + */ |
|
28 | + private $data; |
|
29 | + |
|
30 | + /** |
|
31 | + * Create a new SetCookie object from a string. |
|
32 | + * |
|
33 | + * @param string $cookie Set-Cookie header string |
|
34 | + */ |
|
35 | + public static function fromString(string $cookie): self |
|
36 | + { |
|
37 | + // Create the default return array |
|
38 | + $data = self::$defaults; |
|
39 | + // Explode the cookie string using a series of semicolons |
|
40 | + $pieces = \array_filter(\array_map('trim', \explode(';', $cookie))); |
|
41 | + // The name of the cookie (first kvp) must exist and include an equal sign. |
|
42 | + if (!isset($pieces[0]) || \strpos($pieces[0], '=') === false) { |
|
43 | + return new self($data); |
|
44 | + } |
|
45 | + |
|
46 | + // Add the cookie pieces into the parsed data array |
|
47 | + foreach ($pieces as $part) { |
|
48 | + $cookieParts = \explode('=', $part, 2); |
|
49 | + $key = \trim($cookieParts[0]); |
|
50 | + $value = isset($cookieParts[1]) |
|
51 | + ? \trim($cookieParts[1], " \n\r\t\0\x0B") |
|
52 | + : true; |
|
53 | + |
|
54 | + // Only check for non-cookies when cookies have been found |
|
55 | + if (!isset($data['Name'])) { |
|
56 | + $data['Name'] = $key; |
|
57 | + $data['Value'] = $value; |
|
58 | + } else { |
|
59 | + foreach (\array_keys(self::$defaults) as $search) { |
|
60 | + if (!\strcasecmp($search, $key)) { |
|
61 | + if ($search === 'Max-Age') { |
|
62 | + if (is_numeric($value)) { |
|
63 | + $data[$search] = (int) $value; |
|
64 | + } |
|
65 | + } else { |
|
66 | + $data[$search] = $value; |
|
67 | + } |
|
68 | + continue 2; |
|
69 | + } |
|
70 | + } |
|
71 | + $data[$key] = $value; |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + return new self($data); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @param array $data Array of cookie data provided by a Cookie parser |
|
80 | + */ |
|
81 | + public function __construct(array $data = []) |
|
82 | + { |
|
83 | + $this->data = self::$defaults; |
|
84 | + |
|
85 | + if (isset($data['Name'])) { |
|
86 | + $this->setName($data['Name']); |
|
87 | + } |
|
88 | + |
|
89 | + if (isset($data['Value'])) { |
|
90 | + $this->setValue($data['Value']); |
|
91 | + } |
|
92 | + |
|
93 | + if (isset($data['Domain'])) { |
|
94 | + $this->setDomain($data['Domain']); |
|
95 | + } |
|
96 | + |
|
97 | + if (isset($data['Path'])) { |
|
98 | + $this->setPath($data['Path']); |
|
99 | + } |
|
100 | + |
|
101 | + if (isset($data['Max-Age'])) { |
|
102 | + $this->setMaxAge($data['Max-Age']); |
|
103 | + } |
|
104 | + |
|
105 | + if (isset($data['Expires'])) { |
|
106 | + $this->setExpires($data['Expires']); |
|
107 | + } |
|
108 | + |
|
109 | + if (isset($data['Secure'])) { |
|
110 | + $this->setSecure($data['Secure']); |
|
111 | + } |
|
112 | + |
|
113 | + if (isset($data['Discard'])) { |
|
114 | + $this->setDiscard($data['Discard']); |
|
115 | + } |
|
116 | + |
|
117 | + if (isset($data['HttpOnly'])) { |
|
118 | + $this->setHttpOnly($data['HttpOnly']); |
|
119 | + } |
|
120 | + |
|
121 | + // Set the remaining values that don't have extra validation logic |
|
122 | + foreach (array_diff(array_keys($data), array_keys(self::$defaults)) as $key) { |
|
123 | + $this->data[$key] = $data[$key]; |
|
124 | + } |
|
125 | + |
|
126 | + // Extract the Expires value and turn it into a UNIX timestamp if needed |
|
127 | + if (!$this->getExpires() && $this->getMaxAge()) { |
|
128 | + // Calculate the Expires date |
|
129 | + $this->setExpires(\time() + $this->getMaxAge()); |
|
130 | + } elseif (null !== ($expires = $this->getExpires()) && !\is_numeric($expires)) { |
|
131 | + $this->setExpires($expires); |
|
132 | + } |
|
133 | + } |
|
134 | + |
|
135 | + public function __toString() |
|
136 | + { |
|
137 | + $str = $this->data['Name'].'='.($this->data['Value'] ?? '').'; '; |
|
138 | + foreach ($this->data as $k => $v) { |
|
139 | + if ($k !== 'Name' && $k !== 'Value' && $v !== null && $v !== false) { |
|
140 | + if ($k === 'Expires') { |
|
141 | + $str .= 'Expires='.\gmdate('D, d M Y H:i:s \G\M\T', $v).'; '; |
|
142 | + } else { |
|
143 | + $str .= ($v === true ? $k : "{$k}={$v}").'; '; |
|
144 | + } |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return \rtrim($str, '; '); |
|
149 | + } |
|
150 | + |
|
151 | + public function toArray(): array |
|
152 | + { |
|
153 | + return $this->data; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * Get the cookie name. |
|
158 | + * |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function getName() |
|
162 | + { |
|
163 | + return $this->data['Name']; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Set the cookie name. |
|
168 | + * |
|
169 | + * @param string $name Cookie name |
|
170 | + */ |
|
171 | + public function setName($name): void |
|
172 | + { |
|
173 | + if (!is_string($name)) { |
|
174 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
175 | + } |
|
176 | + |
|
177 | + $this->data['Name'] = (string) $name; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Get the cookie value. |
|
182 | + * |
|
183 | + * @return string|null |
|
184 | + */ |
|
185 | + public function getValue() |
|
186 | + { |
|
187 | + return $this->data['Value']; |
|
188 | + } |
|
189 | + |
|
190 | + /** |
|
191 | + * Set the cookie value. |
|
192 | + * |
|
193 | + * @param string $value Cookie value |
|
194 | + */ |
|
195 | + public function setValue($value): void |
|
196 | + { |
|
197 | + if (!is_string($value)) { |
|
198 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
199 | + } |
|
200 | + |
|
201 | + $this->data['Value'] = (string) $value; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get the domain. |
|
206 | + * |
|
207 | + * @return string|null |
|
208 | + */ |
|
209 | + public function getDomain() |
|
210 | + { |
|
211 | + return $this->data['Domain']; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Set the domain of the cookie. |
|
216 | + * |
|
217 | + * @param string|null $domain |
|
218 | + */ |
|
219 | + public function setDomain($domain): void |
|
220 | + { |
|
221 | + if (!is_string($domain) && null !== $domain) { |
|
222 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
223 | + } |
|
224 | + |
|
225 | + $this->data['Domain'] = null === $domain ? null : (string) $domain; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Get the path. |
|
230 | + * |
|
231 | + * @return string |
|
232 | + */ |
|
233 | + public function getPath() |
|
234 | + { |
|
235 | + return $this->data['Path']; |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Set the path of the cookie. |
|
240 | + * |
|
241 | + * @param string $path Path of the cookie |
|
242 | + */ |
|
243 | + public function setPath($path): void |
|
244 | + { |
|
245 | + if (!is_string($path)) { |
|
246 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
247 | + } |
|
248 | + |
|
249 | + $this->data['Path'] = (string) $path; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Maximum lifetime of the cookie in seconds. |
|
254 | + * |
|
255 | + * @return int|null |
|
256 | + */ |
|
257 | + public function getMaxAge() |
|
258 | + { |
|
259 | + return null === $this->data['Max-Age'] ? null : (int) $this->data['Max-Age']; |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Set the max-age of the cookie. |
|
264 | + * |
|
265 | + * @param int|null $maxAge Max age of the cookie in seconds |
|
266 | + */ |
|
267 | + public function setMaxAge($maxAge): void |
|
268 | + { |
|
269 | + if (!is_int($maxAge) && null !== $maxAge) { |
|
270 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
271 | + } |
|
272 | + |
|
273 | + $this->data['Max-Age'] = $maxAge === null ? null : (int) $maxAge; |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * The UNIX timestamp when the cookie Expires. |
|
278 | + * |
|
279 | + * @return string|int|null |
|
280 | + */ |
|
281 | + public function getExpires() |
|
282 | + { |
|
283 | + return $this->data['Expires']; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Set the unix timestamp for which the cookie will expire. |
|
288 | + * |
|
289 | + * @param int|string|null $timestamp Unix timestamp or any English textual datetime description. |
|
290 | + */ |
|
291 | + public function setExpires($timestamp): void |
|
292 | + { |
|
293 | + if (!is_int($timestamp) && !is_string($timestamp) && null !== $timestamp) { |
|
294 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int, string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
295 | + } |
|
296 | + |
|
297 | + $this->data['Expires'] = null === $timestamp ? null : (\is_numeric($timestamp) ? (int) $timestamp : \strtotime((string) $timestamp)); |
|
298 | + } |
|
299 | + |
|
300 | + /** |
|
301 | + * Get whether or not this is a secure cookie. |
|
302 | + * |
|
303 | + * @return bool |
|
304 | + */ |
|
305 | + public function getSecure() |
|
306 | + { |
|
307 | + return $this->data['Secure']; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Set whether or not the cookie is secure. |
|
312 | + * |
|
313 | + * @param bool $secure Set to true or false if secure |
|
314 | + */ |
|
315 | + public function setSecure($secure): void |
|
316 | + { |
|
317 | + if (!is_bool($secure)) { |
|
318 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
319 | + } |
|
320 | + |
|
321 | + $this->data['Secure'] = (bool) $secure; |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * Get whether or not this is a session cookie. |
|
326 | + * |
|
327 | + * @return bool|null |
|
328 | + */ |
|
329 | + public function getDiscard() |
|
330 | + { |
|
331 | + return $this->data['Discard']; |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Set whether or not this is a session cookie. |
|
336 | + * |
|
337 | + * @param bool $discard Set to true or false if this is a session cookie |
|
338 | + */ |
|
339 | + public function setDiscard($discard): void |
|
340 | + { |
|
341 | + if (!is_bool($discard)) { |
|
342 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
343 | + } |
|
344 | + |
|
345 | + $this->data['Discard'] = (bool) $discard; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Get whether or not this is an HTTP only cookie. |
|
350 | + * |
|
351 | + * @return bool |
|
352 | + */ |
|
353 | + public function getHttpOnly() |
|
354 | + { |
|
355 | + return $this->data['HttpOnly']; |
|
356 | + } |
|
357 | + |
|
358 | + /** |
|
359 | + * Set whether or not this is an HTTP only cookie. |
|
360 | + * |
|
361 | + * @param bool $httpOnly Set to true or false if this is HTTP only |
|
362 | + */ |
|
363 | + public function setHttpOnly($httpOnly): void |
|
364 | + { |
|
365 | + if (!is_bool($httpOnly)) { |
|
366 | + trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
|
367 | + } |
|
368 | + |
|
369 | + $this->data['HttpOnly'] = (bool) $httpOnly; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Check if the cookie matches a path value. |
|
374 | + * |
|
375 | + * A request-path path-matches a given cookie-path if at least one of |
|
376 | + * the following conditions holds: |
|
377 | + * |
|
378 | + * - The cookie-path and the request-path are identical. |
|
379 | + * - The cookie-path is a prefix of the request-path, and the last |
|
380 | + * character of the cookie-path is %x2F ("/"). |
|
381 | + * - The cookie-path is a prefix of the request-path, and the first |
|
382 | + * character of the request-path that is not included in the cookie- |
|
383 | + * path is a %x2F ("/") character. |
|
384 | + * |
|
385 | + * @param string $requestPath Path to check against |
|
386 | + */ |
|
387 | + public function matchesPath(string $requestPath): bool |
|
388 | + { |
|
389 | + $cookiePath = $this->getPath(); |
|
390 | + |
|
391 | + // Match on exact matches or when path is the default empty "/" |
|
392 | + if ($cookiePath === '/' || $cookiePath == $requestPath) { |
|
393 | + return true; |
|
394 | + } |
|
395 | + |
|
396 | + // Ensure that the cookie-path is a prefix of the request path. |
|
397 | + if (0 !== \strpos($requestPath, $cookiePath)) { |
|
398 | + return false; |
|
399 | + } |
|
400 | + |
|
401 | + // Match if the last character of the cookie-path is "/" |
|
402 | + if (\substr($cookiePath, -1, 1) === '/') { |
|
403 | + return true; |
|
404 | + } |
|
405 | + |
|
406 | + // Match if the first character not included in cookie path is "/" |
|
407 | + return \substr($requestPath, \strlen($cookiePath), 1) === '/'; |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Check if the cookie matches a domain value. |
|
412 | + * |
|
413 | + * @param string $domain Domain to check against |
|
414 | + */ |
|
415 | + public function matchesDomain(string $domain): bool |
|
416 | + { |
|
417 | + $cookieDomain = $this->getDomain(); |
|
418 | + if (null === $cookieDomain) { |
|
419 | + return true; |
|
420 | + } |
|
421 | + |
|
422 | + // Remove the leading '.' as per spec in RFC 6265. |
|
423 | + // https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.3 |
|
424 | + $cookieDomain = \ltrim(\strtolower($cookieDomain), '.'); |
|
425 | + |
|
426 | + $domain = \strtolower($domain); |
|
427 | + |
|
428 | + // Domain not set or exact match. |
|
429 | + if ('' === $cookieDomain || $domain === $cookieDomain) { |
|
430 | + return true; |
|
431 | + } |
|
432 | + |
|
433 | + // Matching the subdomain according to RFC 6265. |
|
434 | + // https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.3 |
|
435 | + if (\filter_var($domain, \FILTER_VALIDATE_IP)) { |
|
436 | + return false; |
|
437 | + } |
|
438 | + |
|
439 | + return (bool) \preg_match('/\.'.\preg_quote($cookieDomain, '/').'$/', $domain); |
|
440 | + } |
|
441 | + |
|
442 | + /** |
|
443 | + * Check if the cookie is expired. |
|
444 | + */ |
|
445 | + public function isExpired(): bool |
|
446 | + { |
|
447 | + return $this->getExpires() !== null && \time() > $this->getExpires(); |
|
448 | + } |
|
449 | + |
|
450 | + /** |
|
451 | + * Check if the cookie is valid according to RFC 6265. |
|
452 | + * |
|
453 | + * @return bool|string Returns true if valid or an error message if invalid |
|
454 | + */ |
|
455 | + public function validate() |
|
456 | + { |
|
457 | + $name = $this->getName(); |
|
458 | + if ($name === '') { |
|
459 | + return 'The cookie name must not be empty'; |
|
460 | + } |
|
461 | + |
|
462 | + // Check if any of the invalid characters are present in the cookie name |
|
463 | + if (\preg_match( |
|
464 | + '/[\x00-\x20\x22\x28-\x29\x2c\x2f\x3a-\x40\x5c\x7b\x7d\x7f]/', |
|
465 | + $name |
|
466 | + )) { |
|
467 | + return 'Cookie name must not contain invalid characters: ASCII ' |
|
468 | + .'Control characters (0-31;127), space, tab and the ' |
|
469 | + .'following characters: ()<>@,;:\"/?={}'; |
|
470 | + } |
|
471 | + |
|
472 | + // Value must not be null. 0 and empty string are valid. Empty strings |
|
473 | + // are technically against RFC 6265, but known to happen in the wild. |
|
474 | + $value = $this->getValue(); |
|
475 | + if ($value === null) { |
|
476 | + return 'The cookie value must not be empty'; |
|
477 | + } |
|
478 | + |
|
479 | + // Domains must not be empty, but can be 0. "0" is not a valid internet |
|
480 | + // domain, but may be used as server name in a private network. |
|
481 | + $domain = $this->getDomain(); |
|
482 | + if ($domain === null || $domain === '') { |
|
483 | + return 'The cookie domain must not be empty'; |
|
484 | + } |
|
485 | + |
|
486 | + return true; |
|
487 | + } |
|
488 | 488 | } |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | if (!\strcasecmp($search, $key)) { |
61 | 61 | if ($search === 'Max-Age') { |
62 | 62 | if (is_numeric($value)) { |
63 | - $data[$search] = (int) $value; |
|
63 | + $data[$search] = (int)$value; |
|
64 | 64 | } |
65 | 65 | } else { |
66 | 66 | $data[$search] = $value; |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
175 | 175 | } |
176 | 176 | |
177 | - $this->data['Name'] = (string) $name; |
|
177 | + $this->data['Name'] = (string)$name; |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
199 | 199 | } |
200 | 200 | |
201 | - $this->data['Value'] = (string) $value; |
|
201 | + $this->data['Value'] = (string)$value; |
|
202 | 202 | } |
203 | 203 | |
204 | 204 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
223 | 223 | } |
224 | 224 | |
225 | - $this->data['Domain'] = null === $domain ? null : (string) $domain; |
|
225 | + $this->data['Domain'] = null === $domain ? null : (string)$domain; |
|
226 | 226 | } |
227 | 227 | |
228 | 228 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a string to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
247 | 247 | } |
248 | 248 | |
249 | - $this->data['Path'] = (string) $path; |
|
249 | + $this->data['Path'] = (string)$path; |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function getMaxAge() |
258 | 258 | { |
259 | - return null === $this->data['Max-Age'] ? null : (int) $this->data['Max-Age']; |
|
259 | + return null === $this->data['Max-Age'] ? null : (int)$this->data['Max-Age']; |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
271 | 271 | } |
272 | 272 | |
273 | - $this->data['Max-Age'] = $maxAge === null ? null : (int) $maxAge; |
|
273 | + $this->data['Max-Age'] = $maxAge === null ? null : (int)$maxAge; |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing an int, string or null to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
295 | 295 | } |
296 | 296 | |
297 | - $this->data['Expires'] = null === $timestamp ? null : (\is_numeric($timestamp) ? (int) $timestamp : \strtotime((string) $timestamp)); |
|
297 | + $this->data['Expires'] = null === $timestamp ? null : (\is_numeric($timestamp) ? (int)$timestamp : \strtotime((string)$timestamp)); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
319 | 319 | } |
320 | 320 | |
321 | - $this->data['Secure'] = (bool) $secure; |
|
321 | + $this->data['Secure'] = (bool)$secure; |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | /** |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
343 | 343 | } |
344 | 344 | |
345 | - $this->data['Discard'] = (bool) $discard; |
|
345 | + $this->data['Discard'] = (bool)$discard; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | trigger_deprecation('guzzlehttp/guzzle', '7.4', 'Not passing a bool to %s::%s() is deprecated and will cause an error in 8.0.', __CLASS__, __FUNCTION__); |
367 | 367 | } |
368 | 368 | |
369 | - $this->data['HttpOnly'] = (bool) $httpOnly; |
|
369 | + $this->data['HttpOnly'] = (bool)$httpOnly; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | return false; |
437 | 437 | } |
438 | 438 | |
439 | - return (bool) \preg_match('/\.'.\preg_quote($cookieDomain, '/').'$/', $domain); |
|
439 | + return (bool)\preg_match('/\.'.\preg_quote($cookieDomain, '/').'$/', $domain); |
|
440 | 440 | } |
441 | 441 | |
442 | 442 | /** |
@@ -5,8 +5,7 @@ |
||
5 | 5 | /** |
6 | 6 | * Set-Cookie object |
7 | 7 | */ |
8 | -class SetCookie |
|
9 | -{ |
|
8 | +class SetCookie { |
|
10 | 9 | /** |
11 | 10 | * @var array |
12 | 11 | */ |
@@ -7,71 +7,71 @@ |
||
7 | 7 | */ |
8 | 8 | class SessionCookieJar extends CookieJar |
9 | 9 | { |
10 | - /** |
|
11 | - * @var string session key |
|
12 | - */ |
|
13 | - private $sessionKey; |
|
10 | + /** |
|
11 | + * @var string session key |
|
12 | + */ |
|
13 | + private $sessionKey; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var bool Control whether to persist session cookies or not. |
|
17 | - */ |
|
18 | - private $storeSessionCookies; |
|
15 | + /** |
|
16 | + * @var bool Control whether to persist session cookies or not. |
|
17 | + */ |
|
18 | + private $storeSessionCookies; |
|
19 | 19 | |
20 | - /** |
|
21 | - * Create a new SessionCookieJar object |
|
22 | - * |
|
23 | - * @param string $sessionKey Session key name to store the cookie |
|
24 | - * data in session |
|
25 | - * @param bool $storeSessionCookies Set to true to store session cookies |
|
26 | - * in the cookie jar. |
|
27 | - */ |
|
28 | - public function __construct(string $sessionKey, bool $storeSessionCookies = false) |
|
29 | - { |
|
30 | - parent::__construct(); |
|
31 | - $this->sessionKey = $sessionKey; |
|
32 | - $this->storeSessionCookies = $storeSessionCookies; |
|
33 | - $this->load(); |
|
34 | - } |
|
20 | + /** |
|
21 | + * Create a new SessionCookieJar object |
|
22 | + * |
|
23 | + * @param string $sessionKey Session key name to store the cookie |
|
24 | + * data in session |
|
25 | + * @param bool $storeSessionCookies Set to true to store session cookies |
|
26 | + * in the cookie jar. |
|
27 | + */ |
|
28 | + public function __construct(string $sessionKey, bool $storeSessionCookies = false) |
|
29 | + { |
|
30 | + parent::__construct(); |
|
31 | + $this->sessionKey = $sessionKey; |
|
32 | + $this->storeSessionCookies = $storeSessionCookies; |
|
33 | + $this->load(); |
|
34 | + } |
|
35 | 35 | |
36 | - /** |
|
37 | - * Saves cookies to session when shutting down |
|
38 | - */ |
|
39 | - public function __destruct() |
|
40 | - { |
|
41 | - $this->save(); |
|
42 | - } |
|
36 | + /** |
|
37 | + * Saves cookies to session when shutting down |
|
38 | + */ |
|
39 | + public function __destruct() |
|
40 | + { |
|
41 | + $this->save(); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Save cookies to the client session |
|
46 | - */ |
|
47 | - public function save(): void |
|
48 | - { |
|
49 | - $json = []; |
|
50 | - /** @var SetCookie $cookie */ |
|
51 | - foreach ($this as $cookie) { |
|
52 | - if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { |
|
53 | - $json[] = $cookie->toArray(); |
|
54 | - } |
|
55 | - } |
|
44 | + /** |
|
45 | + * Save cookies to the client session |
|
46 | + */ |
|
47 | + public function save(): void |
|
48 | + { |
|
49 | + $json = []; |
|
50 | + /** @var SetCookie $cookie */ |
|
51 | + foreach ($this as $cookie) { |
|
52 | + if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { |
|
53 | + $json[] = $cookie->toArray(); |
|
54 | + } |
|
55 | + } |
|
56 | 56 | |
57 | - $_SESSION[$this->sessionKey] = \json_encode($json); |
|
58 | - } |
|
57 | + $_SESSION[$this->sessionKey] = \json_encode($json); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Load the contents of the client session into the data array |
|
62 | - */ |
|
63 | - protected function load(): void |
|
64 | - { |
|
65 | - if (!isset($_SESSION[$this->sessionKey])) { |
|
66 | - return; |
|
67 | - } |
|
68 | - $data = \json_decode($_SESSION[$this->sessionKey], true); |
|
69 | - if (\is_array($data)) { |
|
70 | - foreach ($data as $cookie) { |
|
71 | - $this->setCookie(new SetCookie($cookie)); |
|
72 | - } |
|
73 | - } elseif (\strlen($data)) { |
|
74 | - throw new \RuntimeException('Invalid cookie data'); |
|
75 | - } |
|
76 | - } |
|
60 | + /** |
|
61 | + * Load the contents of the client session into the data array |
|
62 | + */ |
|
63 | + protected function load(): void |
|
64 | + { |
|
65 | + if (!isset($_SESSION[$this->sessionKey])) { |
|
66 | + return; |
|
67 | + } |
|
68 | + $data = \json_decode($_SESSION[$this->sessionKey], true); |
|
69 | + if (\is_array($data)) { |
|
70 | + foreach ($data as $cookie) { |
|
71 | + $this->setCookie(new SetCookie($cookie)); |
|
72 | + } |
|
73 | + } elseif (\strlen($data)) { |
|
74 | + throw new \RuntimeException('Invalid cookie data'); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | /** |
6 | 6 | * Persists cookies in the client session |
7 | 7 | */ |
8 | -class SessionCookieJar extends CookieJar |
|
9 | -{ |
|
8 | +class SessionCookieJar extends CookieJar { |
|
10 | 9 | /** |
11 | 10 | * @var string session key |
12 | 11 | */ |
@@ -19,62 +19,62 @@ |
||
19 | 19 | */ |
20 | 20 | interface CookieJarInterface extends \Countable, \IteratorAggregate |
21 | 21 | { |
22 | - /** |
|
23 | - * Create a request with added cookie headers. |
|
24 | - * |
|
25 | - * If no matching cookies are found in the cookie jar, then no Cookie |
|
26 | - * header is added to the request and the same request is returned. |
|
27 | - * |
|
28 | - * @param RequestInterface $request Request object to modify. |
|
29 | - * |
|
30 | - * @return RequestInterface returns the modified request. |
|
31 | - */ |
|
32 | - public function withCookieHeader(RequestInterface $request): RequestInterface; |
|
22 | + /** |
|
23 | + * Create a request with added cookie headers. |
|
24 | + * |
|
25 | + * If no matching cookies are found in the cookie jar, then no Cookie |
|
26 | + * header is added to the request and the same request is returned. |
|
27 | + * |
|
28 | + * @param RequestInterface $request Request object to modify. |
|
29 | + * |
|
30 | + * @return RequestInterface returns the modified request. |
|
31 | + */ |
|
32 | + public function withCookieHeader(RequestInterface $request): RequestInterface; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Extract cookies from an HTTP response and store them in the CookieJar. |
|
36 | - * |
|
37 | - * @param RequestInterface $request Request that was sent |
|
38 | - * @param ResponseInterface $response Response that was received |
|
39 | - */ |
|
40 | - public function extractCookies(RequestInterface $request, ResponseInterface $response): void; |
|
34 | + /** |
|
35 | + * Extract cookies from an HTTP response and store them in the CookieJar. |
|
36 | + * |
|
37 | + * @param RequestInterface $request Request that was sent |
|
38 | + * @param ResponseInterface $response Response that was received |
|
39 | + */ |
|
40 | + public function extractCookies(RequestInterface $request, ResponseInterface $response): void; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Sets a cookie in the cookie jar. |
|
44 | - * |
|
45 | - * @param SetCookie $cookie Cookie to set. |
|
46 | - * |
|
47 | - * @return bool Returns true on success or false on failure |
|
48 | - */ |
|
49 | - public function setCookie(SetCookie $cookie): bool; |
|
42 | + /** |
|
43 | + * Sets a cookie in the cookie jar. |
|
44 | + * |
|
45 | + * @param SetCookie $cookie Cookie to set. |
|
46 | + * |
|
47 | + * @return bool Returns true on success or false on failure |
|
48 | + */ |
|
49 | + public function setCookie(SetCookie $cookie): bool; |
|
50 | 50 | |
51 | - /** |
|
52 | - * Remove cookies currently held in the cookie jar. |
|
53 | - * |
|
54 | - * Invoking this method without arguments will empty the whole cookie jar. |
|
55 | - * If given a $domain argument only cookies belonging to that domain will |
|
56 | - * be removed. If given a $domain and $path argument, cookies belonging to |
|
57 | - * the specified path within that domain are removed. If given all three |
|
58 | - * arguments, then the cookie with the specified name, path and domain is |
|
59 | - * removed. |
|
60 | - * |
|
61 | - * @param string|null $domain Clears cookies matching a domain |
|
62 | - * @param string|null $path Clears cookies matching a domain and path |
|
63 | - * @param string|null $name Clears cookies matching a domain, path, and name |
|
64 | - */ |
|
65 | - public function clear(string $domain = null, string $path = null, string $name = null): void; |
|
51 | + /** |
|
52 | + * Remove cookies currently held in the cookie jar. |
|
53 | + * |
|
54 | + * Invoking this method without arguments will empty the whole cookie jar. |
|
55 | + * If given a $domain argument only cookies belonging to that domain will |
|
56 | + * be removed. If given a $domain and $path argument, cookies belonging to |
|
57 | + * the specified path within that domain are removed. If given all three |
|
58 | + * arguments, then the cookie with the specified name, path and domain is |
|
59 | + * removed. |
|
60 | + * |
|
61 | + * @param string|null $domain Clears cookies matching a domain |
|
62 | + * @param string|null $path Clears cookies matching a domain and path |
|
63 | + * @param string|null $name Clears cookies matching a domain, path, and name |
|
64 | + */ |
|
65 | + public function clear(string $domain = null, string $path = null, string $name = null): void; |
|
66 | 66 | |
67 | - /** |
|
68 | - * Discard all sessions cookies. |
|
69 | - * |
|
70 | - * Removes cookies that don't have an expire field or a have a discard |
|
71 | - * field set to true. To be called when the user agent shuts down according |
|
72 | - * to RFC 2965. |
|
73 | - */ |
|
74 | - public function clearSessionCookies(): void; |
|
67 | + /** |
|
68 | + * Discard all sessions cookies. |
|
69 | + * |
|
70 | + * Removes cookies that don't have an expire field or a have a discard |
|
71 | + * field set to true. To be called when the user agent shuts down according |
|
72 | + * to RFC 2965. |
|
73 | + */ |
|
74 | + public function clearSessionCookies(): void; |
|
75 | 75 | |
76 | - /** |
|
77 | - * Converts the cookie jar to an array. |
|
78 | - */ |
|
79 | - public function toArray(): array; |
|
76 | + /** |
|
77 | + * Converts the cookie jar to an array. |
|
78 | + */ |
|
79 | + public function toArray(): array; |
|
80 | 80 | } |
@@ -9,93 +9,93 @@ |
||
9 | 9 | */ |
10 | 10 | class FileCookieJar extends CookieJar |
11 | 11 | { |
12 | - /** |
|
13 | - * @var string filename |
|
14 | - */ |
|
15 | - private $filename; |
|
12 | + /** |
|
13 | + * @var string filename |
|
14 | + */ |
|
15 | + private $filename; |
|
16 | 16 | |
17 | - /** |
|
18 | - * @var bool Control whether to persist session cookies or not. |
|
19 | - */ |
|
20 | - private $storeSessionCookies; |
|
17 | + /** |
|
18 | + * @var bool Control whether to persist session cookies or not. |
|
19 | + */ |
|
20 | + private $storeSessionCookies; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Create a new FileCookieJar object |
|
24 | - * |
|
25 | - * @param string $cookieFile File to store the cookie data |
|
26 | - * @param bool $storeSessionCookies Set to true to store session cookies |
|
27 | - * in the cookie jar. |
|
28 | - * |
|
29 | - * @throws \RuntimeException if the file cannot be found or created |
|
30 | - */ |
|
31 | - public function __construct(string $cookieFile, bool $storeSessionCookies = false) |
|
32 | - { |
|
33 | - parent::__construct(); |
|
34 | - $this->filename = $cookieFile; |
|
35 | - $this->storeSessionCookies = $storeSessionCookies; |
|
22 | + /** |
|
23 | + * Create a new FileCookieJar object |
|
24 | + * |
|
25 | + * @param string $cookieFile File to store the cookie data |
|
26 | + * @param bool $storeSessionCookies Set to true to store session cookies |
|
27 | + * in the cookie jar. |
|
28 | + * |
|
29 | + * @throws \RuntimeException if the file cannot be found or created |
|
30 | + */ |
|
31 | + public function __construct(string $cookieFile, bool $storeSessionCookies = false) |
|
32 | + { |
|
33 | + parent::__construct(); |
|
34 | + $this->filename = $cookieFile; |
|
35 | + $this->storeSessionCookies = $storeSessionCookies; |
|
36 | 36 | |
37 | - if (\file_exists($cookieFile)) { |
|
38 | - $this->load($cookieFile); |
|
39 | - } |
|
40 | - } |
|
37 | + if (\file_exists($cookieFile)) { |
|
38 | + $this->load($cookieFile); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Saves the file when shutting down |
|
44 | - */ |
|
45 | - public function __destruct() |
|
46 | - { |
|
47 | - $this->save($this->filename); |
|
48 | - } |
|
42 | + /** |
|
43 | + * Saves the file when shutting down |
|
44 | + */ |
|
45 | + public function __destruct() |
|
46 | + { |
|
47 | + $this->save($this->filename); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Saves the cookies to a file. |
|
52 | - * |
|
53 | - * @param string $filename File to save |
|
54 | - * |
|
55 | - * @throws \RuntimeException if the file cannot be found or created |
|
56 | - */ |
|
57 | - public function save(string $filename): void |
|
58 | - { |
|
59 | - $json = []; |
|
60 | - /** @var SetCookie $cookie */ |
|
61 | - foreach ($this as $cookie) { |
|
62 | - if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { |
|
63 | - $json[] = $cookie->toArray(); |
|
64 | - } |
|
65 | - } |
|
50 | + /** |
|
51 | + * Saves the cookies to a file. |
|
52 | + * |
|
53 | + * @param string $filename File to save |
|
54 | + * |
|
55 | + * @throws \RuntimeException if the file cannot be found or created |
|
56 | + */ |
|
57 | + public function save(string $filename): void |
|
58 | + { |
|
59 | + $json = []; |
|
60 | + /** @var SetCookie $cookie */ |
|
61 | + foreach ($this as $cookie) { |
|
62 | + if (CookieJar::shouldPersist($cookie, $this->storeSessionCookies)) { |
|
63 | + $json[] = $cookie->toArray(); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | - $jsonStr = Utils::jsonEncode($json); |
|
68 | - if (false === \file_put_contents($filename, $jsonStr, \LOCK_EX)) { |
|
69 | - throw new \RuntimeException("Unable to save file {$filename}"); |
|
70 | - } |
|
71 | - } |
|
67 | + $jsonStr = Utils::jsonEncode($json); |
|
68 | + if (false === \file_put_contents($filename, $jsonStr, \LOCK_EX)) { |
|
69 | + throw new \RuntimeException("Unable to save file {$filename}"); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Load cookies from a JSON formatted file. |
|
75 | - * |
|
76 | - * Old cookies are kept unless overwritten by newly loaded ones. |
|
77 | - * |
|
78 | - * @param string $filename Cookie file to load. |
|
79 | - * |
|
80 | - * @throws \RuntimeException if the file cannot be loaded. |
|
81 | - */ |
|
82 | - public function load(string $filename): void |
|
83 | - { |
|
84 | - $json = \file_get_contents($filename); |
|
85 | - if (false === $json) { |
|
86 | - throw new \RuntimeException("Unable to load file {$filename}"); |
|
87 | - } |
|
88 | - if ($json === '') { |
|
89 | - return; |
|
90 | - } |
|
73 | + /** |
|
74 | + * Load cookies from a JSON formatted file. |
|
75 | + * |
|
76 | + * Old cookies are kept unless overwritten by newly loaded ones. |
|
77 | + * |
|
78 | + * @param string $filename Cookie file to load. |
|
79 | + * |
|
80 | + * @throws \RuntimeException if the file cannot be loaded. |
|
81 | + */ |
|
82 | + public function load(string $filename): void |
|
83 | + { |
|
84 | + $json = \file_get_contents($filename); |
|
85 | + if (false === $json) { |
|
86 | + throw new \RuntimeException("Unable to load file {$filename}"); |
|
87 | + } |
|
88 | + if ($json === '') { |
|
89 | + return; |
|
90 | + } |
|
91 | 91 | |
92 | - $data = Utils::jsonDecode($json, true); |
|
93 | - if (\is_array($data)) { |
|
94 | - foreach ($data as $cookie) { |
|
95 | - $this->setCookie(new SetCookie($cookie)); |
|
96 | - } |
|
97 | - } elseif (\is_scalar($data) && !empty($data)) { |
|
98 | - throw new \RuntimeException("Invalid cookie file: {$filename}"); |
|
99 | - } |
|
100 | - } |
|
92 | + $data = Utils::jsonDecode($json, true); |
|
93 | + if (\is_array($data)) { |
|
94 | + foreach ($data as $cookie) { |
|
95 | + $this->setCookie(new SetCookie($cookie)); |
|
96 | + } |
|
97 | + } elseif (\is_scalar($data) && !empty($data)) { |
|
98 | + throw new \RuntimeException("Invalid cookie file: {$filename}"); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | } |
@@ -7,8 +7,7 @@ |
||
7 | 7 | /** |
8 | 8 | * Persists non-session cookies using a JSON formatted file |
9 | 9 | */ |
10 | -class FileCookieJar extends CookieJar |
|
11 | -{ |
|
10 | +class FileCookieJar extends CookieJar { |
|
12 | 11 | /** |
13 | 12 | * @var string filename |
14 | 13 | */ |
@@ -10,298 +10,298 @@ |
||
10 | 10 | */ |
11 | 11 | class CookieJar implements CookieJarInterface |
12 | 12 | { |
13 | - /** |
|
14 | - * @var SetCookie[] Loaded cookie data |
|
15 | - */ |
|
16 | - private $cookies = []; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var bool |
|
20 | - */ |
|
21 | - private $strictMode; |
|
22 | - |
|
23 | - /** |
|
24 | - * @param bool $strictMode Set to true to throw exceptions when invalid |
|
25 | - * cookies are added to the cookie jar. |
|
26 | - * @param array $cookieArray Array of SetCookie objects or a hash of |
|
27 | - * arrays that can be used with the SetCookie |
|
28 | - * constructor |
|
29 | - */ |
|
30 | - public function __construct(bool $strictMode = false, array $cookieArray = []) |
|
31 | - { |
|
32 | - $this->strictMode = $strictMode; |
|
33 | - |
|
34 | - foreach ($cookieArray as $cookie) { |
|
35 | - if (!($cookie instanceof SetCookie)) { |
|
36 | - $cookie = new SetCookie($cookie); |
|
37 | - } |
|
38 | - $this->setCookie($cookie); |
|
39 | - } |
|
40 | - } |
|
41 | - |
|
42 | - /** |
|
43 | - * Create a new Cookie jar from an associative array and domain. |
|
44 | - * |
|
45 | - * @param array $cookies Cookies to create the jar from |
|
46 | - * @param string $domain Domain to set the cookies to |
|
47 | - */ |
|
48 | - public static function fromArray(array $cookies, string $domain): self |
|
49 | - { |
|
50 | - $cookieJar = new self(); |
|
51 | - foreach ($cookies as $name => $value) { |
|
52 | - $cookieJar->setCookie(new SetCookie([ |
|
53 | - 'Domain' => $domain, |
|
54 | - 'Name' => $name, |
|
55 | - 'Value' => $value, |
|
56 | - 'Discard' => true, |
|
57 | - ])); |
|
58 | - } |
|
59 | - |
|
60 | - return $cookieJar; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Evaluate if this cookie should be persisted to storage |
|
65 | - * that survives between requests. |
|
66 | - * |
|
67 | - * @param SetCookie $cookie Being evaluated. |
|
68 | - * @param bool $allowSessionCookies If we should persist session cookies |
|
69 | - */ |
|
70 | - public static function shouldPersist(SetCookie $cookie, bool $allowSessionCookies = false): bool |
|
71 | - { |
|
72 | - if ($cookie->getExpires() || $allowSessionCookies) { |
|
73 | - if (!$cookie->getDiscard()) { |
|
74 | - return true; |
|
75 | - } |
|
76 | - } |
|
77 | - |
|
78 | - return false; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Finds and returns the cookie based on the name |
|
83 | - * |
|
84 | - * @param string $name cookie name to search for |
|
85 | - * |
|
86 | - * @return SetCookie|null cookie that was found or null if not found |
|
87 | - */ |
|
88 | - public function getCookieByName(string $name): ?SetCookie |
|
89 | - { |
|
90 | - foreach ($this->cookies as $cookie) { |
|
91 | - if ($cookie->getName() !== null && \strcasecmp($cookie->getName(), $name) === 0) { |
|
92 | - return $cookie; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - return null; |
|
97 | - } |
|
98 | - |
|
99 | - public function toArray(): array |
|
100 | - { |
|
101 | - return \array_map(static function (SetCookie $cookie): array { |
|
102 | - return $cookie->toArray(); |
|
103 | - }, $this->getIterator()->getArrayCopy()); |
|
104 | - } |
|
105 | - |
|
106 | - public function clear(string $domain = null, string $path = null, string $name = null): void |
|
107 | - { |
|
108 | - if (!$domain) { |
|
109 | - $this->cookies = []; |
|
110 | - |
|
111 | - return; |
|
112 | - } elseif (!$path) { |
|
113 | - $this->cookies = \array_filter( |
|
114 | - $this->cookies, |
|
115 | - static function (SetCookie $cookie) use ($domain): bool { |
|
116 | - return !$cookie->matchesDomain($domain); |
|
117 | - } |
|
118 | - ); |
|
119 | - } elseif (!$name) { |
|
120 | - $this->cookies = \array_filter( |
|
121 | - $this->cookies, |
|
122 | - static function (SetCookie $cookie) use ($path, $domain): bool { |
|
123 | - return !($cookie->matchesPath($path) |
|
124 | - && $cookie->matchesDomain($domain)); |
|
125 | - } |
|
126 | - ); |
|
127 | - } else { |
|
128 | - $this->cookies = \array_filter( |
|
129 | - $this->cookies, |
|
130 | - static function (SetCookie $cookie) use ($path, $domain, $name) { |
|
131 | - return !($cookie->getName() == $name |
|
132 | - && $cookie->matchesPath($path) |
|
133 | - && $cookie->matchesDomain($domain)); |
|
134 | - } |
|
135 | - ); |
|
136 | - } |
|
137 | - } |
|
138 | - |
|
139 | - public function clearSessionCookies(): void |
|
140 | - { |
|
141 | - $this->cookies = \array_filter( |
|
142 | - $this->cookies, |
|
143 | - static function (SetCookie $cookie): bool { |
|
144 | - return !$cookie->getDiscard() && $cookie->getExpires(); |
|
145 | - } |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - public function setCookie(SetCookie $cookie): bool |
|
150 | - { |
|
151 | - // If the name string is empty (but not 0), ignore the set-cookie |
|
152 | - // string entirely. |
|
153 | - $name = $cookie->getName(); |
|
154 | - if (!$name && $name !== '0') { |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - // Only allow cookies with set and valid domain, name, value |
|
159 | - $result = $cookie->validate(); |
|
160 | - if ($result !== true) { |
|
161 | - if ($this->strictMode) { |
|
162 | - throw new \RuntimeException('Invalid cookie: '.$result); |
|
163 | - } |
|
164 | - $this->removeCookieIfEmpty($cookie); |
|
165 | - |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - // Resolve conflicts with previously set cookies |
|
170 | - foreach ($this->cookies as $i => $c) { |
|
171 | - // Two cookies are identical, when their path, and domain are |
|
172 | - // identical. |
|
173 | - if ($c->getPath() != $cookie->getPath() |
|
174 | - || $c->getDomain() != $cookie->getDomain() |
|
175 | - || $c->getName() != $cookie->getName() |
|
176 | - ) { |
|
177 | - continue; |
|
178 | - } |
|
179 | - |
|
180 | - // The previously set cookie is a discard cookie and this one is |
|
181 | - // not so allow the new cookie to be set |
|
182 | - if (!$cookie->getDiscard() && $c->getDiscard()) { |
|
183 | - unset($this->cookies[$i]); |
|
184 | - continue; |
|
185 | - } |
|
186 | - |
|
187 | - // If the new cookie's expiration is further into the future, then |
|
188 | - // replace the old cookie |
|
189 | - if ($cookie->getExpires() > $c->getExpires()) { |
|
190 | - unset($this->cookies[$i]); |
|
191 | - continue; |
|
192 | - } |
|
193 | - |
|
194 | - // If the value has changed, we better change it |
|
195 | - if ($cookie->getValue() !== $c->getValue()) { |
|
196 | - unset($this->cookies[$i]); |
|
197 | - continue; |
|
198 | - } |
|
199 | - |
|
200 | - // The cookie exists, so no need to continue |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - $this->cookies[] = $cookie; |
|
205 | - |
|
206 | - return true; |
|
207 | - } |
|
208 | - |
|
209 | - public function count(): int |
|
210 | - { |
|
211 | - return \count($this->cookies); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * @return \ArrayIterator<int, SetCookie> |
|
216 | - */ |
|
217 | - public function getIterator(): \ArrayIterator |
|
218 | - { |
|
219 | - return new \ArrayIterator(\array_values($this->cookies)); |
|
220 | - } |
|
221 | - |
|
222 | - public function extractCookies(RequestInterface $request, ResponseInterface $response): void |
|
223 | - { |
|
224 | - if ($cookieHeader = $response->getHeader('Set-Cookie')) { |
|
225 | - foreach ($cookieHeader as $cookie) { |
|
226 | - $sc = SetCookie::fromString($cookie); |
|
227 | - if (!$sc->getDomain()) { |
|
228 | - $sc->setDomain($request->getUri()->getHost()); |
|
229 | - } |
|
230 | - if (0 !== \strpos($sc->getPath(), '/')) { |
|
231 | - $sc->setPath($this->getCookiePathFromRequest($request)); |
|
232 | - } |
|
233 | - if (!$sc->matchesDomain($request->getUri()->getHost())) { |
|
234 | - continue; |
|
235 | - } |
|
236 | - // Note: At this point `$sc->getDomain()` being a public suffix should |
|
237 | - // be rejected, but we don't want to pull in the full PSL dependency. |
|
238 | - $this->setCookie($sc); |
|
239 | - } |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Computes cookie path following RFC 6265 section 5.1.4 |
|
245 | - * |
|
246 | - * @see https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.4 |
|
247 | - */ |
|
248 | - private function getCookiePathFromRequest(RequestInterface $request): string |
|
249 | - { |
|
250 | - $uriPath = $request->getUri()->getPath(); |
|
251 | - if ('' === $uriPath) { |
|
252 | - return '/'; |
|
253 | - } |
|
254 | - if (0 !== \strpos($uriPath, '/')) { |
|
255 | - return '/'; |
|
256 | - } |
|
257 | - if ('/' === $uriPath) { |
|
258 | - return '/'; |
|
259 | - } |
|
260 | - $lastSlashPos = \strrpos($uriPath, '/'); |
|
261 | - if (0 === $lastSlashPos || false === $lastSlashPos) { |
|
262 | - return '/'; |
|
263 | - } |
|
264 | - |
|
265 | - return \substr($uriPath, 0, $lastSlashPos); |
|
266 | - } |
|
267 | - |
|
268 | - public function withCookieHeader(RequestInterface $request): RequestInterface |
|
269 | - { |
|
270 | - $values = []; |
|
271 | - $uri = $request->getUri(); |
|
272 | - $scheme = $uri->getScheme(); |
|
273 | - $host = $uri->getHost(); |
|
274 | - $path = $uri->getPath() ?: '/'; |
|
275 | - |
|
276 | - foreach ($this->cookies as $cookie) { |
|
277 | - if ($cookie->matchesPath($path) |
|
278 | - && $cookie->matchesDomain($host) |
|
279 | - && !$cookie->isExpired() |
|
280 | - && (!$cookie->getSecure() || $scheme === 'https') |
|
281 | - ) { |
|
282 | - $values[] = $cookie->getName().'=' |
|
283 | - .$cookie->getValue(); |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - return $values |
|
288 | - ? $request->withHeader('Cookie', \implode('; ', $values)) |
|
289 | - : $request; |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * If a cookie already exists and the server asks to set it again with a |
|
294 | - * null value, the cookie must be deleted. |
|
295 | - */ |
|
296 | - private function removeCookieIfEmpty(SetCookie $cookie): void |
|
297 | - { |
|
298 | - $cookieValue = $cookie->getValue(); |
|
299 | - if ($cookieValue === null || $cookieValue === '') { |
|
300 | - $this->clear( |
|
301 | - $cookie->getDomain(), |
|
302 | - $cookie->getPath(), |
|
303 | - $cookie->getName() |
|
304 | - ); |
|
305 | - } |
|
306 | - } |
|
13 | + /** |
|
14 | + * @var SetCookie[] Loaded cookie data |
|
15 | + */ |
|
16 | + private $cookies = []; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var bool |
|
20 | + */ |
|
21 | + private $strictMode; |
|
22 | + |
|
23 | + /** |
|
24 | + * @param bool $strictMode Set to true to throw exceptions when invalid |
|
25 | + * cookies are added to the cookie jar. |
|
26 | + * @param array $cookieArray Array of SetCookie objects or a hash of |
|
27 | + * arrays that can be used with the SetCookie |
|
28 | + * constructor |
|
29 | + */ |
|
30 | + public function __construct(bool $strictMode = false, array $cookieArray = []) |
|
31 | + { |
|
32 | + $this->strictMode = $strictMode; |
|
33 | + |
|
34 | + foreach ($cookieArray as $cookie) { |
|
35 | + if (!($cookie instanceof SetCookie)) { |
|
36 | + $cookie = new SetCookie($cookie); |
|
37 | + } |
|
38 | + $this->setCookie($cookie); |
|
39 | + } |
|
40 | + } |
|
41 | + |
|
42 | + /** |
|
43 | + * Create a new Cookie jar from an associative array and domain. |
|
44 | + * |
|
45 | + * @param array $cookies Cookies to create the jar from |
|
46 | + * @param string $domain Domain to set the cookies to |
|
47 | + */ |
|
48 | + public static function fromArray(array $cookies, string $domain): self |
|
49 | + { |
|
50 | + $cookieJar = new self(); |
|
51 | + foreach ($cookies as $name => $value) { |
|
52 | + $cookieJar->setCookie(new SetCookie([ |
|
53 | + 'Domain' => $domain, |
|
54 | + 'Name' => $name, |
|
55 | + 'Value' => $value, |
|
56 | + 'Discard' => true, |
|
57 | + ])); |
|
58 | + } |
|
59 | + |
|
60 | + return $cookieJar; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Evaluate if this cookie should be persisted to storage |
|
65 | + * that survives between requests. |
|
66 | + * |
|
67 | + * @param SetCookie $cookie Being evaluated. |
|
68 | + * @param bool $allowSessionCookies If we should persist session cookies |
|
69 | + */ |
|
70 | + public static function shouldPersist(SetCookie $cookie, bool $allowSessionCookies = false): bool |
|
71 | + { |
|
72 | + if ($cookie->getExpires() || $allowSessionCookies) { |
|
73 | + if (!$cookie->getDiscard()) { |
|
74 | + return true; |
|
75 | + } |
|
76 | + } |
|
77 | + |
|
78 | + return false; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Finds and returns the cookie based on the name |
|
83 | + * |
|
84 | + * @param string $name cookie name to search for |
|
85 | + * |
|
86 | + * @return SetCookie|null cookie that was found or null if not found |
|
87 | + */ |
|
88 | + public function getCookieByName(string $name): ?SetCookie |
|
89 | + { |
|
90 | + foreach ($this->cookies as $cookie) { |
|
91 | + if ($cookie->getName() !== null && \strcasecmp($cookie->getName(), $name) === 0) { |
|
92 | + return $cookie; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + return null; |
|
97 | + } |
|
98 | + |
|
99 | + public function toArray(): array |
|
100 | + { |
|
101 | + return \array_map(static function (SetCookie $cookie): array { |
|
102 | + return $cookie->toArray(); |
|
103 | + }, $this->getIterator()->getArrayCopy()); |
|
104 | + } |
|
105 | + |
|
106 | + public function clear(string $domain = null, string $path = null, string $name = null): void |
|
107 | + { |
|
108 | + if (!$domain) { |
|
109 | + $this->cookies = []; |
|
110 | + |
|
111 | + return; |
|
112 | + } elseif (!$path) { |
|
113 | + $this->cookies = \array_filter( |
|
114 | + $this->cookies, |
|
115 | + static function (SetCookie $cookie) use ($domain): bool { |
|
116 | + return !$cookie->matchesDomain($domain); |
|
117 | + } |
|
118 | + ); |
|
119 | + } elseif (!$name) { |
|
120 | + $this->cookies = \array_filter( |
|
121 | + $this->cookies, |
|
122 | + static function (SetCookie $cookie) use ($path, $domain): bool { |
|
123 | + return !($cookie->matchesPath($path) |
|
124 | + && $cookie->matchesDomain($domain)); |
|
125 | + } |
|
126 | + ); |
|
127 | + } else { |
|
128 | + $this->cookies = \array_filter( |
|
129 | + $this->cookies, |
|
130 | + static function (SetCookie $cookie) use ($path, $domain, $name) { |
|
131 | + return !($cookie->getName() == $name |
|
132 | + && $cookie->matchesPath($path) |
|
133 | + && $cookie->matchesDomain($domain)); |
|
134 | + } |
|
135 | + ); |
|
136 | + } |
|
137 | + } |
|
138 | + |
|
139 | + public function clearSessionCookies(): void |
|
140 | + { |
|
141 | + $this->cookies = \array_filter( |
|
142 | + $this->cookies, |
|
143 | + static function (SetCookie $cookie): bool { |
|
144 | + return !$cookie->getDiscard() && $cookie->getExpires(); |
|
145 | + } |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + public function setCookie(SetCookie $cookie): bool |
|
150 | + { |
|
151 | + // If the name string is empty (but not 0), ignore the set-cookie |
|
152 | + // string entirely. |
|
153 | + $name = $cookie->getName(); |
|
154 | + if (!$name && $name !== '0') { |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + // Only allow cookies with set and valid domain, name, value |
|
159 | + $result = $cookie->validate(); |
|
160 | + if ($result !== true) { |
|
161 | + if ($this->strictMode) { |
|
162 | + throw new \RuntimeException('Invalid cookie: '.$result); |
|
163 | + } |
|
164 | + $this->removeCookieIfEmpty($cookie); |
|
165 | + |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + // Resolve conflicts with previously set cookies |
|
170 | + foreach ($this->cookies as $i => $c) { |
|
171 | + // Two cookies are identical, when their path, and domain are |
|
172 | + // identical. |
|
173 | + if ($c->getPath() != $cookie->getPath() |
|
174 | + || $c->getDomain() != $cookie->getDomain() |
|
175 | + || $c->getName() != $cookie->getName() |
|
176 | + ) { |
|
177 | + continue; |
|
178 | + } |
|
179 | + |
|
180 | + // The previously set cookie is a discard cookie and this one is |
|
181 | + // not so allow the new cookie to be set |
|
182 | + if (!$cookie->getDiscard() && $c->getDiscard()) { |
|
183 | + unset($this->cookies[$i]); |
|
184 | + continue; |
|
185 | + } |
|
186 | + |
|
187 | + // If the new cookie's expiration is further into the future, then |
|
188 | + // replace the old cookie |
|
189 | + if ($cookie->getExpires() > $c->getExpires()) { |
|
190 | + unset($this->cookies[$i]); |
|
191 | + continue; |
|
192 | + } |
|
193 | + |
|
194 | + // If the value has changed, we better change it |
|
195 | + if ($cookie->getValue() !== $c->getValue()) { |
|
196 | + unset($this->cookies[$i]); |
|
197 | + continue; |
|
198 | + } |
|
199 | + |
|
200 | + // The cookie exists, so no need to continue |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + $this->cookies[] = $cookie; |
|
205 | + |
|
206 | + return true; |
|
207 | + } |
|
208 | + |
|
209 | + public function count(): int |
|
210 | + { |
|
211 | + return \count($this->cookies); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * @return \ArrayIterator<int, SetCookie> |
|
216 | + */ |
|
217 | + public function getIterator(): \ArrayIterator |
|
218 | + { |
|
219 | + return new \ArrayIterator(\array_values($this->cookies)); |
|
220 | + } |
|
221 | + |
|
222 | + public function extractCookies(RequestInterface $request, ResponseInterface $response): void |
|
223 | + { |
|
224 | + if ($cookieHeader = $response->getHeader('Set-Cookie')) { |
|
225 | + foreach ($cookieHeader as $cookie) { |
|
226 | + $sc = SetCookie::fromString($cookie); |
|
227 | + if (!$sc->getDomain()) { |
|
228 | + $sc->setDomain($request->getUri()->getHost()); |
|
229 | + } |
|
230 | + if (0 !== \strpos($sc->getPath(), '/')) { |
|
231 | + $sc->setPath($this->getCookiePathFromRequest($request)); |
|
232 | + } |
|
233 | + if (!$sc->matchesDomain($request->getUri()->getHost())) { |
|
234 | + continue; |
|
235 | + } |
|
236 | + // Note: At this point `$sc->getDomain()` being a public suffix should |
|
237 | + // be rejected, but we don't want to pull in the full PSL dependency. |
|
238 | + $this->setCookie($sc); |
|
239 | + } |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Computes cookie path following RFC 6265 section 5.1.4 |
|
245 | + * |
|
246 | + * @see https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.4 |
|
247 | + */ |
|
248 | + private function getCookiePathFromRequest(RequestInterface $request): string |
|
249 | + { |
|
250 | + $uriPath = $request->getUri()->getPath(); |
|
251 | + if ('' === $uriPath) { |
|
252 | + return '/'; |
|
253 | + } |
|
254 | + if (0 !== \strpos($uriPath, '/')) { |
|
255 | + return '/'; |
|
256 | + } |
|
257 | + if ('/' === $uriPath) { |
|
258 | + return '/'; |
|
259 | + } |
|
260 | + $lastSlashPos = \strrpos($uriPath, '/'); |
|
261 | + if (0 === $lastSlashPos || false === $lastSlashPos) { |
|
262 | + return '/'; |
|
263 | + } |
|
264 | + |
|
265 | + return \substr($uriPath, 0, $lastSlashPos); |
|
266 | + } |
|
267 | + |
|
268 | + public function withCookieHeader(RequestInterface $request): RequestInterface |
|
269 | + { |
|
270 | + $values = []; |
|
271 | + $uri = $request->getUri(); |
|
272 | + $scheme = $uri->getScheme(); |
|
273 | + $host = $uri->getHost(); |
|
274 | + $path = $uri->getPath() ?: '/'; |
|
275 | + |
|
276 | + foreach ($this->cookies as $cookie) { |
|
277 | + if ($cookie->matchesPath($path) |
|
278 | + && $cookie->matchesDomain($host) |
|
279 | + && !$cookie->isExpired() |
|
280 | + && (!$cookie->getSecure() || $scheme === 'https') |
|
281 | + ) { |
|
282 | + $values[] = $cookie->getName().'=' |
|
283 | + .$cookie->getValue(); |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + return $values |
|
288 | + ? $request->withHeader('Cookie', \implode('; ', $values)) |
|
289 | + : $request; |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * If a cookie already exists and the server asks to set it again with a |
|
294 | + * null value, the cookie must be deleted. |
|
295 | + */ |
|
296 | + private function removeCookieIfEmpty(SetCookie $cookie): void |
|
297 | + { |
|
298 | + $cookieValue = $cookie->getValue(); |
|
299 | + if ($cookieValue === null || $cookieValue === '') { |
|
300 | + $this->clear( |
|
301 | + $cookie->getDomain(), |
|
302 | + $cookie->getPath(), |
|
303 | + $cookie->getName() |
|
304 | + ); |
|
305 | + } |
|
306 | + } |
|
307 | 307 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | public function toArray(): array |
100 | 100 | { |
101 | - return \array_map(static function (SetCookie $cookie): array { |
|
101 | + return \array_map(static function(SetCookie $cookie): array { |
|
102 | 102 | return $cookie->toArray(); |
103 | 103 | }, $this->getIterator()->getArrayCopy()); |
104 | 104 | } |
@@ -112,14 +112,14 @@ discard block |
||
112 | 112 | } elseif (!$path) { |
113 | 113 | $this->cookies = \array_filter( |
114 | 114 | $this->cookies, |
115 | - static function (SetCookie $cookie) use ($domain): bool { |
|
115 | + static function(SetCookie $cookie) use ($domain): bool { |
|
116 | 116 | return !$cookie->matchesDomain($domain); |
117 | 117 | } |
118 | 118 | ); |
119 | 119 | } elseif (!$name) { |
120 | 120 | $this->cookies = \array_filter( |
121 | 121 | $this->cookies, |
122 | - static function (SetCookie $cookie) use ($path, $domain): bool { |
|
122 | + static function(SetCookie $cookie) use ($path, $domain): bool { |
|
123 | 123 | return !($cookie->matchesPath($path) |
124 | 124 | && $cookie->matchesDomain($domain)); |
125 | 125 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | } else { |
128 | 128 | $this->cookies = \array_filter( |
129 | 129 | $this->cookies, |
130 | - static function (SetCookie $cookie) use ($path, $domain, $name) { |
|
130 | + static function(SetCookie $cookie) use ($path, $domain, $name) { |
|
131 | 131 | return !($cookie->getName() == $name |
132 | 132 | && $cookie->matchesPath($path) |
133 | 133 | && $cookie->matchesDomain($domain)); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | { |
141 | 141 | $this->cookies = \array_filter( |
142 | 142 | $this->cookies, |
143 | - static function (SetCookie $cookie): bool { |
|
143 | + static function(SetCookie $cookie): bool { |
|
144 | 144 | return !$cookie->getDiscard() && $cookie->getExpires(); |
145 | 145 | } |
146 | 146 | ); |
@@ -8,8 +8,7 @@ |
||
8 | 8 | /** |
9 | 9 | * Cookie jar that stores cookies as an array |
10 | 10 | */ |
11 | -class CookieJar implements CookieJarInterface |
|
12 | -{ |
|
11 | +class CookieJar implements CookieJarInterface { |
|
13 | 12 | /** |
14 | 13 | * @var SetCookie[] Loaded cookie data |
15 | 14 | */ |
@@ -2,6 +2,5 @@ |
||
2 | 2 | |
3 | 3 | namespace OCA\FullTextSearch_Elasticsearch\Vendor\GuzzleHttp\Exception; |
4 | 4 | |
5 | -class TooManyRedirectsException extends RequestException |
|
6 | -{ |
|
5 | +class TooManyRedirectsException extends RequestException { |
|
7 | 6 | } |
@@ -5,6 +5,5 @@ |
||
5 | 5 | /** |
6 | 6 | * Exception when a client error is encountered (4xx codes) |
7 | 7 | */ |
8 | -class ClientException extends BadResponseException |
|
9 | -{ |
|
8 | +class ClientException extends BadResponseException { |
|
10 | 9 | } |