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
Copy file name to clipboardExpand all lines: README.md
+25-20Lines changed: 25 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -42,26 +42,43 @@ A collection of utilities for use with [PSR-7 Message implementations](https://w
42
42
Profit!
43
43
44
44
## API
45
+
The following classes contain static methods for use with PSR-7 http message objects.
45
46
46
-
### `Header`
47
-
The `Header` class contains static methods for use with http request and response headers.
48
-
47
+
### `HeaderUtil`
49
48
method | return | info
50
49
------ | ------ | ----
51
50
`normalize(array $headers)` | `array` | Normalizes an array of header lines to format `["Name" => "Value (, Value2, Value3, ...)", ...]` An exception is being made for `Set-Cookie`, which holds an array of values for each cookie. For multiple cookies with the same name, only the last value will be kept.
52
51
53
-
### `Query`
54
-
The `Query` class contains static methods for use with http query strings.
55
-
52
+
### `QueryUtil`
56
53
method | return | info
57
54
------ | ------ | ----
58
55
`cleanParams(iterable $params, int $bool_cast = null, bool $remove_empty = null)` | `array` | Cleans/normalizes an array of query parameters, booleans will be converted according to the given `$bool_cast` constant. By default, booleans will be left as-is (`Query::BOOLEANS_AS_BOOL`) and may result in empty values. If `$remove_empty` is set to true, empty non-boolean and null values will be removed from the array. The `Query` class provides the following constants for `$bool_cast`:<br>`BOOLEANS_AS_BOOL`: unchanged boolean value (default)<br>`BOOLEANS_AS_INT`: integer values 0 or 1<br>`BOOLEANS_AS_STRING`: "true"/"false" strings<br>`BOOLEANS_AS_INT_STRING`: "0"/"1" strings
59
56
`build(array $params, int $encoding = null, string $delimiter = null, string $enclosure = null)` | `string` | Builds a query string from an array of key value pairs, similar to [`http_build_query`](https://www.php.net/manual/en/function.http-build-query). Valid values for `$encoding` are `PHP_QUERY_RFC3986` (default) and `PHP_QUERY_RFC1738`, any other integer value will be interpreted as "no encoding" (`Query::NO_ENCODING`).
60
57
`merge(string $uri, array $query)` | `string` | Merges additional query parameters into an existing query string.
61
58
`parse(string $querystring, int $urlEncoding = null)` | `array` | Parses a query string into an associative array, similar to [`parse_str`](https://www.php.net/manual/en/function.parse-str) (without the inconvenient usage of a by-reference result variable).
`decodeJSON(MessageInterface $message, bool $assoc = null)` | mixed | fetches the body of a `MessageInterface` and converts it to a JSON object (`stdClass`) or an associative array if `$assoc` is set to `true` and returns the result.
65
+
`decodeXML(MessageInterface $message, bool $assoc = null)` | mixed | fetches the body of a `MessageInterface` and converts it to a `SimpleXMLElement` or an associative array if `$assoc` is set to `true` and returns the result.
66
+
`toString(MessageInterface $message)` | `string` | Returns the string representation of an HTTP message.
67
+
`decompress(MessageInterface $message)` | `string` | Decompresses the message content according to the `Content-Encoding` header (`compress`, `deflate`, `gzip`, `br`) and returns the decompressed data. For a [`br` (Brotli)](https://en.wikipedia.org/wiki/Brotli) extension see: https://github.com/kjdev/php-ext-brotli
68
+
69
+
### `UriUtil`
70
+
method | return | info
71
+
------ | ------ | ----
72
+
`isDefaultPort(UriInterface $uri)` | `bool` | Checks whether the `UriInterface` has a port set and if that port is one of the default ports for the given scheme.
73
+
`isAbsolute(UriInterface $uri)` | `bool` | Checks Whether the URI is absolute, i.e. it has a scheme.
74
+
`isNetworkPathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a network-path reference.
75
+
`isAbsolutePathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a absolute-path reference.
76
+
`isRelativePathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a relative-path reference.
77
+
`withoutQueryValue(UriInterface $uri, string $key)` | `UriInterface` | Removes a specific query string value. Any existing query string values that exactly match the provided `$key` are removed.
78
+
`withQueryValue(UriInterface $uri, string $key, string $value = null)` | `UriInterface` | Adds a specific query string value. Any existing query string values that exactly match the provided `$key` are removed and replaced with the given `$key`-`$value` pair. A value of null will set the query string key without a value, e.g. "key" instead of "key=value".
62
79
63
-
### `Server`
64
-
The `Server` object requires a set of [PSR-17 factories](https://www.php-fig.org/psr/psr-17/) on invocation, namely `ServerRequestFactoryInterface`, `UriFactoryInterface`, `UploadedFileFactoryInterface` and `StreamFactoryInterface`.
80
+
### `ServerUtil`
81
+
The `ServerUtil` object requires a set of [PSR-17 factories](https://www.php-fig.org/psr/psr-17/) on invocation, namely `ServerRequestFactoryInterface`, `UriFactoryInterface`, `UploadedFileFactoryInterface` and `StreamFactoryInterface`.
65
82
It provides convenience methods to create server requests, URIs and uploaded files from the [superglobals](https://www.php.net/manual/en/language.variables.superglobals.php).
66
83
67
84
method | return | info
@@ -80,15 +97,3 @@ function | return | info
80
97
`getMimetypeFromExtension(string $extension)` | `?string` | Get the mime type for the given file extension (checks against the constant `chillerlan\HTTP\Utils\MIMETYPES`, a list of mime types from the [apache default config](http://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x/conf/mime.types))
81
98
`getMimetypeFromFilename(string $filename)` | `?string` | Get the mime type from a file name
`get_json(MessageInterface $message, bool $assoc = null)` | mixed | fetches the body of a `MessageInterface` and converts it to a JSON object (`stdClass`) or an associative array if `$assoc` is set to `true` and returns the result.
84
-
`get_xml(MessageInterface $message, bool $assoc = null)` | mixed | fetches the body of a `MessageInterface` and converts it to a `SimpleXMLElement` or an associative array if `$assoc` is set to `true` and returns the result.
85
-
`message_to_string(MessageInterface $message)` | `string` | Returns the string representation of an HTTP message.
86
-
`decompress_content(MessageInterface $message)` | `string` | Decompresses the message content according to the `Content-Encoding` header (`compress`, `deflate`, `gzip`, `br`) and returns the decompressed data. For a [`br` (Brotli)](https://en.wikipedia.org/wiki/Brotli) extension see: https://github.com/kjdev/php-ext-brotli
87
-
`uriIsDefaultPort(UriInterface $uri)` | `bool` | Checks whether the `UriInterface` has a port set and if that port is one of the default ports for the given scheme.
88
-
`uriIsAbsolute(UriInterface $uri)` | `bool` | Checks Whether the URI is absolute, i.e. it has a scheme.
89
-
`uriIsNetworkPathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a network-path reference.
90
-
`uriIsAbsolutePathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a absolute-path reference.
91
-
`uriIsRelativePathReference(UriInterface $uri)` | `bool` | Checks Whether the URI is a relative-path reference.
92
-
`uriWithoutQueryValue(UriInterface $uri, string $key)` | `UriInterface` | Removes a specific query string value. Any existing query string values that exactly match the provided `$key` are removed.
93
-
`uriWithQueryValue(UriInterface $uri, string $key, string $value = null)` | `UriInterface` | Adds a specific query string value. Any existing query string values that exactly match the provided `$key` are removed and replaced with the given `$key`-`$value` pair. A value of null will set the query string key without a value, e.g. "key" instead of "key=value".
0 commit comments