You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`clean_query_params(iterable $params, int $bool_cast = null, bool $remove_empty = null)` | clean an array of parameters for URL queries (or JSON output etc.) using the following cast formats:<br>`BOOLEANS_AS_BOOL` - bool types will be left untouched (default)<br>`BOOLEANS_AS_INT` - cast to integer `1` and `0`<br>`BOOLEANS_AS_STRING` - a string value `"true"` and `"false"`<br>`BOOLEANS_AS_INT_STRING` - integer values, but as string, `"1"` and `"0"`
66
+
`merge_query(string $uri, array $query)` | merges an array of query parameters into an URL query string
`message_to_string(MessageInterface $message)` | returns the string representation of a `MessageInterface`
73
+
`decompress_content(MessageInterface $message)` | decompresses the message content according to the `Content-Encoding` header and returns the decompressed data
74
+
75
+
### [PSR-15](https://www.php-fig.org/psr/psr-15/) Request handlers and middleware
76
+
These classes can be found in the `chillerlan\HTTP\Psr15` namespace:
A `HTTPClientInterface` is usually invoked with a [`HTTPOptions`](https://github.com/chillerlan/php-httpinterface/blob/master/src/HTTPOptions.php) object as the first (optional) parameter,
59
-
and - depending on the client - followed by one or more optional [PSR-17](https://www.php-fig.org/psr/psr-17/) message factories.
88
+
```php
89
+
// an iterable that contains several PSR-15 MiddlewareInterfaces
90
+
$middlewareStack = [
91
+
// ...
92
+
];
93
+
94
+
// Fallback handler, using a PSR-17 ResponseFactory:
95
+
$fallbackHandler = new EmptyResponseHandler($responseFactoryInterface, 200);
96
+
97
+
// Create request handler instance:
98
+
$handler = new QueueRequestHandler($middlewareStack, $fallbackHandler);
The `PriorityQueueRequestHandler` works similar, with the difference that it also accepts `PriorityMiddlewareInterface` in the middleware stack, which allows you to specify a priority to control the order of execution.
These classes can be found in the `chillerlan\HTTP\Psr18` namespace:
120
+
121
+
class | description
122
+
------|------------
123
+
`CurlClient` | a native cURL client
124
+
`StreamClient` | a client that uses PHP's stream methods (still requires cURL)
125
+
`URLExtractor` | a client that resolves shortened links (such as `t.co` or `goo.gl`) and returns the response for the last (deepest) URL
126
+
`LoggingClient` | a logger client that wraps another `ClientInterface` and utilizes a `LoggerInterface` to log the request and response objects
127
+
128
+
The namespace `chillerlan\HTTP\CurlUtils` contains several classes related to `CurlClient`
129
+
130
+
class | description
131
+
------|------------
132
+
`CurlHandle` | used in `CurlClient` and `CurlMultiClient`
133
+
`CurlMultiClient` | a `curl_multi` / "[Rolling Curl](http://www.onlineaspect.com/2009/01/26/how-to-use-curl_multi-without-blocking/)" implementation
134
+
`MultiResponseHandlerInterface` | the response handler for `CurlMultiClient`
135
+
136
+
#### HTTP client example
137
+
The built-in HTTP clients are usually invoked with a [`HTTPOptions`](https://github.com/chillerlan/php-httpinterface/blob/master/src/HTTPOptions.php) object as the first (optional) parameter,
138
+
and - depending on the client - followed by one or more optional [PSR-17](https://www.php-fig.org/psr/psr-17/) message factories and a
139
+
PSR-3 `LoggerInterface`.
60
140
```php
61
141
$options = new HTTPOptions([
62
142
'ca_info' => '/path/to/cacert.pem',
@@ -65,46 +145,12 @@ $options = new HTTPOptions([
65
145
66
146
$http = new CurlClient($options, $myResponseFactory);
67
147
```
68
-
You can now fire a request via the implemented [PSR-18](https://www.php-fig.org/psr/psr-18/) method `ClientInterface::sendRequest()`,
69
-
using an existing [PSR-7](https://www.php-fig.org/psr/psr-7/)`RequestInterface`...
148
+
You can now fire a request via the implemented PSR-18 method `ClientInterface::sendRequest()`,
149
+
using an existing PSR-7`RequestInterface` and expect a PSR-7 `ResponseInterface`.
70
150
```php
71
151
use chillerlan\HTTP\Psr7\Request;
72
152
73
153
$request = new Request('GET', 'https://www.example.com?foo=bar');
74
154
75
155
$http->sendRequest($request);
76
156
```
77
-
...or you can use the `HTTPClientInterface::request()` method, which creates a new request using the provided (if any) factories.
78
-
The `HTTPClientInterface` also provides constants for the HTTP methods via the [`RequestMethodInterface`](https://github.com/php-fig/http-message-util/blob/master/src/RequestMethodInterface.php).
-`clean_query_params(iterable $params, int $bool_cast = null, bool $remove_empty = null)` - clean an array of parameters for URL queries (or JSON output etc.) using the following cast formats:
91
-
-`BOOLEANS_AS_BOOL` - bool types will be left untouched (default)
92
-
-`BOOLEANS_AS_INT` - cast to integer `1` and `0`
93
-
-`BOOLEANS_AS_STRING` - a string value `"true"` and `"false"`
94
-
-`BOOLEANS_AS_INT_STRING` - integer values, but as string, `"1"` and `"0"`
95
-
-`merge_query(string $uri, array $query)` - merges an array of parameters into an URL query string
-`message_to_string(MessageInterface $message)` - returns the string representation of a `MessageInterface`
102
-
-`decompress_content(MessageInterface $message)` - decompresses the message content according to the `Content-Encoding` header and returns the decompressed data
0 commit comments