From 85f6d39316950ba2bbd2fa2e024358b58017be43 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Mon, 6 Nov 2017 13:59:59 +0100 Subject: [PATCH] prepare 1.2.0 release --- CHANGELOG.md | 18 +++ src/Components/AbstractComponent.php | 2 +- .../AbstractHierarchicalComponent.php | 2 +- src/Components/ComponentInterface.php | 2 +- src/Components/ComponentTrait.php | 2 +- src/Components/DataPath.php | 2 +- src/Components/EncodingInterface.php | 2 +- src/Components/Exception.php | 2 +- src/Components/Fragment.php | 2 +- src/Components/HierarchicalPath.php | 2 +- src/Components/Host.php | 2 +- src/Components/HostInfoTrait.php | 2 +- src/Components/Path.php | 2 +- src/Components/PathInfoTrait.php | 2 +- src/Components/Port.php | 2 +- src/Components/Query.php | 2 +- src/Components/QueryParserTrait.php | 2 +- src/Components/Scheme.php | 2 +- src/Components/UserInfo.php | 2 +- src/functions.php | 32 +++-- tests/FunctionsTest.php | 118 ++++++++++++++++++ 21 files changed, 178 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c1968d6..681fa0869 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,24 @@ All Notable changes to `League\Uri\Components` will be documented in this file +## 1.2.0 - 2017-11-06 + +### Added + +- `League\Uri\build_query` as an alias of `Query::build` + +### Fixed + +- function docblocks + +### Deprecated + +- None + +### Remove + +- None + ## 1.1.1 - 2017-11-03 ### Added diff --git a/src/Components/AbstractComponent.php b/src/Components/AbstractComponent.php index 95a85ec89..4b5e2c298 100644 --- a/src/Components/AbstractComponent.php +++ b/src/Components/AbstractComponent.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/AbstractHierarchicalComponent.php b/src/Components/AbstractHierarchicalComponent.php index 386f01317..8719ffd44 100644 --- a/src/Components/AbstractHierarchicalComponent.php +++ b/src/Components/AbstractHierarchicalComponent.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/ComponentInterface.php b/src/Components/ComponentInterface.php index 2bfd888ec..dbe25bfee 100644 --- a/src/Components/ComponentInterface.php +++ b/src/Components/ComponentInterface.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-interfaces/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-interfaces/ * diff --git a/src/Components/ComponentTrait.php b/src/Components/ComponentTrait.php index 52abfc0aa..858add9fa 100644 --- a/src/Components/ComponentTrait.php +++ b/src/Components/ComponentTrait.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/DataPath.php b/src/Components/DataPath.php index 343681664..0defe15ca 100644 --- a/src/Components/DataPath.php +++ b/src/Components/DataPath.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/EncodingInterface.php b/src/Components/EncodingInterface.php index 0998416a1..d16792f86 100644 --- a/src/Components/EncodingInterface.php +++ b/src/Components/EncodingInterface.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-interfaces/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-interfaces/ * diff --git a/src/Components/Exception.php b/src/Components/Exception.php index b244af3df..3cf190a29 100644 --- a/src/Components/Exception.php +++ b/src/Components/Exception.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Fragment.php b/src/Components/Fragment.php index 229e9f4e2..e9df5e6b8 100644 --- a/src/Components/Fragment.php +++ b/src/Components/Fragment.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/HierarchicalPath.php b/src/Components/HierarchicalPath.php index 210290ae9..f5e98b212 100644 --- a/src/Components/HierarchicalPath.php +++ b/src/Components/HierarchicalPath.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Host.php b/src/Components/Host.php index 3c098963a..06912f5d8 100644 --- a/src/Components/Host.php +++ b/src/Components/Host.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/HostInfoTrait.php b/src/Components/HostInfoTrait.php index ea94ee745..d2bebc20d 100644 --- a/src/Components/HostInfoTrait.php +++ b/src/Components/HostInfoTrait.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Path.php b/src/Components/Path.php index 0ceadb592..784fb79b3 100644 --- a/src/Components/Path.php +++ b/src/Components/Path.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/PathInfoTrait.php b/src/Components/PathInfoTrait.php index 3218260cf..6147d188f 100644 --- a/src/Components/PathInfoTrait.php +++ b/src/Components/PathInfoTrait.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Port.php b/src/Components/Port.php index 5917ed355..268133811 100644 --- a/src/Components/Port.php +++ b/src/Components/Port.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Query.php b/src/Components/Query.php index e503b1f79..fd64ed7e2 100644 --- a/src/Components/Query.php +++ b/src/Components/Query.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/QueryParserTrait.php b/src/Components/QueryParserTrait.php index 2271a332c..983e13417 100644 --- a/src/Components/QueryParserTrait.php +++ b/src/Components/QueryParserTrait.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/Scheme.php b/src/Components/Scheme.php index 0fc7549ef..6338782e0 100644 --- a/src/Components/Scheme.php +++ b/src/Components/Scheme.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/Components/UserInfo.php b/src/Components/UserInfo.php index 7e9a02046..9c79fcc4c 100644 --- a/src/Components/UserInfo.php +++ b/src/Components/UserInfo.php @@ -6,7 +6,7 @@ * @subpackage League\Uri\Components * @author Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-components/blob/master/LICENSE (MIT License) - * @version 1.1.1 + * @version 1.2.0 * @link https://github.com/thephpleague/uri-components * diff --git a/src/functions.php b/src/functions.php index 55f9ba33e..517afb5ac 100644 --- a/src/functions.php +++ b/src/functions.php @@ -16,13 +16,29 @@ use League\Uri\Components\Query; /** - * Parse the query string like parse_str without mangling the results + * Build a query string from an associative array * - * @see Query::extract + * @see Query::build + * + * @param array $pairs The query pairs + * @param string $separator The query string separator + * @param int $enc_type The query encoding type + * + * @return string + */ +function build_query(array $pairs, string $separator = '&', int $enc_type = PHP_QUERY_RFC3986): string +{ + return Query::build($pairs, $separator, $enc_type); +} + +/** + * Parse a query string into an associative array + * + * @see Query::parse * - * @param string $query - * @param string $separator - * @param int $enc_type + * @param string $query The query string to parse + * @param string $separator The query string separator + * @param int $enc_type The query encoding algorithm * * @return array */ @@ -36,9 +52,9 @@ function parse_query(string $query, string $separator = '&', int $enc_type = PHP * * @see Query::extract * - * @param string $query - * @param string $separator - * @param int $enc_type + * @param string $query The query string to parse + * @param string $separator The query string separator + * @param int $enc_type The query encoding algorithm * * @return array */ diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 942860ac2..a7124b794 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -202,4 +202,122 @@ public function parserProvider() ], ]; } + + /** + * @dataProvider buildProvider + * @param array $pairs + * @param string $expected_rfc1738 + * @param string $expected_rfc3986 + * @param string $expected_rfc3987 + * @param string $expected_no_encoding + */ + public function testBuild( + $pairs, + $expected_rfc1738, + $expected_rfc3986, + $expected_rfc3987, + $expected_no_encoding + ) { + $this->assertSame($expected_rfc1738, Uri\build_query($pairs, '&', PHP_QUERY_RFC1738)); + $this->assertSame($expected_rfc3986, Uri\build_query($pairs, '&', PHP_QUERY_RFC3986)); + $this->assertSame($expected_rfc3987, Uri\build_query($pairs, '&', Query::RFC3987_ENCODING)); + $this->assertSame($expected_no_encoding, Uri\build_query($pairs, '&', Query::NO_ENCODING)); + } + + public function buildProvider() + { + return [ + 'empty string' => [ + 'pairs' => [], + 'expected_rfc1738' => '', + 'expected_rfc3986' => '', + 'expected_rfc3987' => '', + 'expected_no_encoding' => '', + ], + 'identical keys' => [ + 'pairs' => ['a' => ['1', '2']], + 'expected_rfc1738' => 'a=1&a=2', + 'expected_rfc3986' => 'a=1&a=2', + 'expected_rfc3987' => 'a=1&a=2', + 'expected_no_encoding' => 'a=1&a=2', + ], + 'no value' => [ + 'pairs' => ['a' => null, 'b' => null], + 'expected_rfc1738' => 'a&b', + 'expected_rfc3986' => 'a&b', + 'expected_rfc3987' => 'a&b', + 'expected_no_encoding' => 'a&b', + ], + 'empty value' => [ + 'pairs' => ['a' => '', 'b' => ''], + 'expected_rfc1738' => 'a=&b=', + 'expected_rfc3986' => 'a=&b=', + 'expected_rfc3987' => 'a=&b=', + 'expected_no_encoding' => 'a=&b=', + ], + 'php array' => [ + 'pairs' => ['a[]' => ['1', '2']], + 'expected_rfc1738' => 'a%5B%5D=1&a%5B%5D=2', + 'expected_rfc3986' => 'a%5B%5D=1&a%5B%5D=2', + 'expected_rfc3987' => 'a[]=1&a[]=2', + 'expected_no_encoding' => 'a[]=1&a[]=2', + ], + 'preserve dot' => [ + 'pairs' => ['a.b' => '3'], + 'expected_rfc1738' => 'a.b=3', + 'expected_rfc3986' => 'a.b=3', + 'expected_rfc3987' => 'a.b=3', + 'expected_no_encoding' => 'a.b=3', + ], + 'no key stripping' => [ + 'pairs' => ['a' => '', 'b' => null], + 'expected_rfc1738' => 'a=&b', + 'expected_rfc3986' => 'a=&b', + 'expected_rfc3987' => 'a=&b', + 'expected_no_encoding' => 'a=&b', + ], + 'no value stripping' => [ + 'pairs' => ['a' => 'b='], + 'expected_rfc1738' => 'a=b=', + 'expected_rfc3986' => 'a=b=', + 'expected_rfc3987' => 'a=b=', + 'expected_no_encoding' => 'a=b=', + ], + 'key only' => [ + 'pairs' => ['a' => null], + 'expected_rfc1738' => 'a', + 'expected_rfc3986' => 'a', + 'expected_rfc3987' => 'a', + 'expected_no_encoding' => 'a', + ], + 'preserve falsey 1' => [ + 'pairs' => ['0' => null], + 'expected_rfc1738' => '0', + 'expected_rfc3986' => '0', + 'expected_rfc3987' => '0', + 'expected_no_encoding' => '0', + ], + 'preserve falsey 2' => [ + 'pairs' => ['0' => ''], + 'expected_rfc1738' => '0=', + 'expected_rfc3986' => '0=', + 'expected_rfc3987' => '0=', + 'expected_no_encoding' => '0=', + ], + 'preserve falsey 3' => [ + 'pairs' => ['0' => '0'], + 'expected_rfc1738' => '0=0', + 'expected_rfc3986' => '0=0', + 'expected_rfc3987' => '0=0', + 'expected_no_encoding' => '0=0', + ], + 'rcf1738' => [ + 'pairs' => ['toto' => 'foo+bar'], + 'expected_rfc1738' => 'toto=foo%2Bbar', + 'expected_rfc3986' => 'toto=foo+bar', + 'expected_rfc3987' => 'toto=foo+bar', + 'expected_no_encoding' => 'toto=foo+bar', + ], + ]; + } }