Skip to content

Commit

Permalink
Prepare 7.1 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Aug 21, 2023
1 parent 3e34e6d commit 0d5742e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All Notable changes to `League\Uri\Components` will be documented in this file

## Next - TBD
## 7.1.0 - 2023-08-21

### Added

Expand Down
2 changes: 1 addition & 1 deletion components/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
],
"require": {
"php": "^8.1",
"league/uri": "^7.0"
"league/uri": "^7.1"
},
"suggest": {
"ext-bcmath": "to improve IPV4 host parsing",
Expand Down
40 changes: 40 additions & 0 deletions docs/components/7.0/modifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,46 @@ The following modifiers update and normalize the URI query component.
resulting query string may update the component character encoding. These changes are expected because of
the rules governing parsing and building query string.</p>

### Modifier::encodeQuery

<p class="message-notice">since version <code>7.1.0</code></p>

Change the encoding of the query string. You can either specify one of PHP's constant between `PHP_QUERY_RFC1738` and
`PHP_QUERY_RFC3986`

~~~php
use League\Uri\Modifier;

echo Modifier::from("https://example.com/?kingkong=toto&foo=bar%20baz&kingkong=ape")
->encodeQuery(PHP_QUERY_RFC1738)
->getUri()
->getQuery();
//display "kingkong=toto&kingkong=ape&foo=bar+baz"
~~~

or for more specific conversions you can provide a `League\Uri\KeyValuePair\Converter` class.

~~~php
use League\Uri\KeyValuePair\Converter as KeyValuePairConverter;
use League\Uri\Modifier;
use Nyholm\Psr7\Uri;

$converter = KeyValuePairConverter::new(';')
->withEncodingMap([
'%3F' => '?',
'%2F' => '/',
'%40' => '@',
'%3A' => ':',
]);

Modifier::from(new Uri('https://example.com?foo[2]=bar#fragment'))
->appendQuery('url=https://example.com?foo[2]=bar#fragment')
->encodeQuery($converter)
->getUri()
->getQuery();
//display "foo%5B2%5D=bar;url=https://example.com?foo%5B2%5D%3Dbar%23fragment"
~~~

### Modifier::sortQuery

Sorts the query according to its key values. The sorting rules are the same uses by WHATWG `URLSearchParams::sort` method.
Expand Down
40 changes: 39 additions & 1 deletion docs/interfaces/7.0/query-parser-builder.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ Query Parser and Builder
=======

The `League\Uri\QueryString` is a PHP URI query parser and builder.
<p class="message-notice">The parsing/building algorithms preserve pairs order and uses the same algorithm used by JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams">UrlSearchParams</a></p>

<p class="message-notice">The parsing/building algorithms preserve pairs order and uses the same algorithm used by
JavaScript <a href="https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams/URLSearchParams">UrlSearchParams</a></p>

```php
<?php
Expand Down Expand Up @@ -42,6 +44,7 @@ $pairs = QueryString::parse('module=home&action=show&page=😓');

```php
<?php
use League\Uri\KeyValuePair\Converter;

public static function QueryString::parse($query, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): array;
```
Expand Down Expand Up @@ -161,6 +164,41 @@ parse_str($query, $variables);
// ];
```

## Advance usages

Starting with version <code>7.1</code> you can have an improved control over the characters conversion
by using the `League\Uri\KeyValuePair\Converter` class. The class is responsible for parsing the string into key/value
pair and for converting key/value pairs into string adding an extra string replacement before parsing and
after building the string.

```php
use League\Uri\KeyValuePair\Converter as KeyValuePairConverter;
use League\Uri\QueryString;

$converter = KeyValuePairConverter::new(';')
->withEncodingMap([
'%3F' => '?',
'%2F' => '/',
'%40' => '@',
'%3A' => ':',
'%5B' => '[',
'%5D' => ']',
'%3D' => '=',
'%23' => '#',
]);

$keyValuePairs = QueryString::parseFromValue('foo=bar&url=https://example.com?foo[2]=bar#fragment');

echo QueryString::buildFromPairs($keyValuePairs, $converter));
// displays foo=bar;url=https://example.com?foo[2]=bar#fragment
```

You can use the class on the following methods as the second argument:

- `buildFromPairs` improved version of `build`
- `extractFromValue` improved version of `extract`
- `parseFromValue` improved version of `parse`

## Exceptions

All exceptions extend the `League\Uri\Exceptions\UriException` marker class which extends PHP's `Throwable` class.
Expand Down
4 changes: 2 additions & 2 deletions interfaces/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All Notable changes to `League\Uri\Interfaces` will be documented in this file

## Next - TBD
## 7.1.0 - 2023-08-21

### Added

Expand All @@ -11,7 +11,7 @@ All Notable changes to `League\Uri\Interfaces` will be documented in this file

### Fixed

- Rewrite `QueryString` classes and fix query encoding for basic RFC3986.
- Rewrite `QueryString` classes and fix query encoding for basic RFC3986. [#109](https://github.com/thephpleague/uri-src/issues/109)

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion uri/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All Notable changes to `League\Uri` will be documented in this file

## Next - TBD
## 7.1.0 - 2023-08-21

### Added

Expand Down
2 changes: 1 addition & 1 deletion uri/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
],
"require": {
"php": "^8.1",
"league/uri-interfaces": "^7.0"
"league/uri-interfaces": "^7.1"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit 0d5742e

Please sign in to comment.