From 3865dace6e078bc8bef74934c14c3fb30d90f765 Mon Sep 17 00:00:00 2001 From: Ignace Nyamagana Butera Date: Fri, 2 Feb 2018 14:54:13 +0100 Subject: [PATCH] prepare 1.4.0 release --- CHANGELOG.md | 24 ++++++- composer.json | 2 +- src/Modifiers/AddBasePath.php | 2 +- src/Modifiers/AddLeadingSlash.php | 2 +- src/Modifiers/AddRootLabel.php | 2 +- src/Modifiers/AddTrailingSlash.php | 2 +- src/Modifiers/AppendLabel.php | 2 +- src/Modifiers/AppendQuery.php | 2 +- src/Modifiers/AppendSegment.php | 2 +- src/Modifiers/Basename.php | 2 +- src/Modifiers/CallableAdapter.php | 2 +- src/Modifiers/DataUriParameters.php | 2 +- src/Modifiers/DataUriToAscii.php | 2 +- src/Modifiers/DataUriToBinary.php | 2 +- src/Modifiers/DecodeUnreservedCharacters.php | 2 +- src/Modifiers/Dirname.php | 2 +- src/Modifiers/Exception.php | 2 +- src/Modifiers/Extension.php | 2 +- src/Modifiers/Formatter.php | 11 +-- src/Modifiers/HostMiddlewareTrait.php | 2 +- src/Modifiers/HostToAscii.php | 2 +- src/Modifiers/HostToUnicode.php | 2 +- src/Modifiers/KsortQuery.php | 2 +- src/Modifiers/MergeQuery.php | 2 +- src/Modifiers/Normalize.php | 2 +- src/Modifiers/PathMiddlewareTrait.php | 2 +- src/Modifiers/Pipeline.php | 2 +- src/Modifiers/PrependLabel.php | 2 +- src/Modifiers/PrependSegment.php | 2 +- src/Modifiers/PublicSuffix.php | 73 ++++++++++++++++++++ src/Modifiers/QueryMiddlewareTrait.php | 2 +- src/Modifiers/RegisterableDomain.php | 19 +++-- src/Modifiers/RemoveBasePath.php | 2 +- src/Modifiers/RemoveDotSegments.php | 2 +- src/Modifiers/RemoveEmptySegments.php | 2 +- src/Modifiers/RemoveLabels.php | 2 +- src/Modifiers/RemoveLeadingSlash.php | 2 +- src/Modifiers/RemoveQueryKeys.php | 2 +- src/Modifiers/RemoveQueryParams.php | 2 +- src/Modifiers/RemoveRootLabel.php | 2 +- src/Modifiers/RemoveSegments.php | 2 +- src/Modifiers/RemoveTrailingSlash.php | 2 +- src/Modifiers/RemoveZoneIdentifier.php | 2 +- src/Modifiers/ReplaceLabel.php | 2 +- src/Modifiers/ReplaceSegment.php | 2 +- src/Modifiers/Resolve.php | 2 +- src/Modifiers/Subdomain.php | 19 +++-- src/Modifiers/UriMiddlewareInterface.php | 2 +- src/Modifiers/UriMiddlewareTrait.php | 10 +-- src/functions.php | 29 ++++++-- tests/HostModifierTest.php | 19 +++++ 51 files changed, 222 insertions(+), 68 deletions(-) create mode 100644 src/Modifiers/PublicSuffix.php diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c9f44b..2939b03f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,28 @@ - All Notable changes to `uri-manipulations` will be documented in this file +## 1.4.0 - TDB + +### Added + +- `League\Uri\Modifiers\PublicSuffix` +- `League\Uri\replace_publicsuffix` + +### Fixed + +- `League\Uri\replace_registrabledomain` now can take a optional `League\Uri\PublicSuffix\Rules` object +- `League\Uri\replace_subdomain` now can take a optional `League\Uri\PublicSuffix\Rules` object +- `League\Uri\Modifiers\RegisterableDomain` constructor now can take a optional `League\Uri\PublicSuffix\Rules` object +- `League\Uri\Modifiers\SubDomain` constructor now can take a optional `League\Uri\PublicSuffix\Rules` object + +### Deprecated + +- None + +### Removed + +- None + ## 1.3.0 - 2017-11-24 ### Added @@ -19,7 +41,7 @@ ### Removed -- Nonce +- None ## 1.2.0 - 2017-11-22 diff --git a/composer.json b/composer.json index 36dc64ee..a0006046 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ }, "minimun-stability" : "dev", "require": { - "league/uri-components": "^1.4.1", + "league/uri-components": "^1.7.0", "league/uri-interfaces": "^1.0", "php" : ">=7.0", "psr/http-message": "^1.0" diff --git a/src/Modifiers/AddBasePath.php b/src/Modifiers/AddBasePath.php index 91690ab8..9491db39 100644 --- a/src/Modifiers/AddBasePath.php +++ b/src/Modifiers/AddBasePath.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AddLeadingSlash.php b/src/Modifiers/AddLeadingSlash.php index f9a459ee..afa5ed54 100644 --- a/src/Modifiers/AddLeadingSlash.php +++ b/src/Modifiers/AddLeadingSlash.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AddRootLabel.php b/src/Modifiers/AddRootLabel.php index 2d429980..23ffd8d7 100644 --- a/src/Modifiers/AddRootLabel.php +++ b/src/Modifiers/AddRootLabel.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AddTrailingSlash.php b/src/Modifiers/AddTrailingSlash.php index 56a272fd..ddba1bc2 100644 --- a/src/Modifiers/AddTrailingSlash.php +++ b/src/Modifiers/AddTrailingSlash.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AppendLabel.php b/src/Modifiers/AppendLabel.php index 566a7ee1..b2d05236 100644 --- a/src/Modifiers/AppendLabel.php +++ b/src/Modifiers/AppendLabel.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AppendQuery.php b/src/Modifiers/AppendQuery.php index 7f9892f0..6097495a 100644 --- a/src/Modifiers/AppendQuery.php +++ b/src/Modifiers/AppendQuery.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/AppendSegment.php b/src/Modifiers/AppendSegment.php index 1a85af49..09d39926 100644 --- a/src/Modifiers/AppendSegment.php +++ b/src/Modifiers/AppendSegment.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Basename.php b/src/Modifiers/Basename.php index 2292ae25..faaca295 100644 --- a/src/Modifiers/Basename.php +++ b/src/Modifiers/Basename.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/CallableAdapter.php b/src/Modifiers/CallableAdapter.php index 69438052..76de14d3 100644 --- a/src/Modifiers/CallableAdapter.php +++ b/src/Modifiers/CallableAdapter.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/DataUriParameters.php b/src/Modifiers/DataUriParameters.php index abaa1642..f8c89d3d 100644 --- a/src/Modifiers/DataUriParameters.php +++ b/src/Modifiers/DataUriParameters.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/DataUriToAscii.php b/src/Modifiers/DataUriToAscii.php index 555fec50..a4827a1c 100644 --- a/src/Modifiers/DataUriToAscii.php +++ b/src/Modifiers/DataUriToAscii.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/DataUriToBinary.php b/src/Modifiers/DataUriToBinary.php index cb1214f6..98c3b4ab 100644 --- a/src/Modifiers/DataUriToBinary.php +++ b/src/Modifiers/DataUriToBinary.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/DecodeUnreservedCharacters.php b/src/Modifiers/DecodeUnreservedCharacters.php index 4b00e645..8f2634ce 100644 --- a/src/Modifiers/DecodeUnreservedCharacters.php +++ b/src/Modifiers/DecodeUnreservedCharacters.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Dirname.php b/src/Modifiers/Dirname.php index 06a1ac4d..aa7231b5 100644 --- a/src/Modifiers/Dirname.php +++ b/src/Modifiers/Dirname.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Exception.php b/src/Modifiers/Exception.php index fb4081a8..01a8fa64 100644 --- a/src/Modifiers/Exception.php +++ b/src/Modifiers/Exception.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Extension.php b/src/Modifiers/Extension.php index cfa59abb..ea2ffb1d 100644 --- a/src/Modifiers/Extension.php +++ b/src/Modifiers/Extension.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Formatter.php b/src/Modifiers/Formatter.php index e8cd2a8a..3794b3aa 100644 --- a/src/Modifiers/Formatter.php +++ b/src/Modifiers/Formatter.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); @@ -15,6 +15,7 @@ namespace League\Uri\Modifiers; use InvalidArgumentException; +use League\Uri; use League\Uri\Components\ComponentInterface; use League\Uri\Components\EncodingInterface; use League\Uri\Components\Fragment; @@ -22,7 +23,7 @@ use League\Uri\Components\Path; use League\Uri\Components\Query; use League\Uri\Components\UserInfo; -use League\Uri\Interfaces\Uri; +use League\Uri\Interfaces\Uri as LeagueUriInterface; use Psr\Http\Message\UriInterface; /** @@ -145,14 +146,14 @@ public function preserveFragment(bool $status) public function __invoke($input) { if ($input instanceof Query) { - return Query::build($input->getPairs(), $this->query_separator, $this->enc_type); + return Uri\build_query($input->getPairs(), $this->query_separator, $this->enc_type); } if ($input instanceof ComponentInterface) { return $input->getContent($this->enc_type); } - if ($input instanceof Uri || $input instanceof UriInterface) { + if ($input instanceof LeagueUriInterface || $input instanceof UriInterface) { return $this->formatUri($input); } @@ -212,7 +213,7 @@ protected function formatUri($uri): string $query = $uri->getQuery(); if ('' != $query || $this->preserve_query) { - $query = '?'.Query::build(Query::parse((string) $query), $this->query_separator, $this->enc_type); + $query = '?'.Uri\build_query(Uri\parse_query((string) $query), $this->query_separator, $this->enc_type); } $fragment = $uri->getFragment(); diff --git a/src/Modifiers/HostMiddlewareTrait.php b/src/Modifiers/HostMiddlewareTrait.php index 1ade4cb4..0afc6bfd 100644 --- a/src/Modifiers/HostMiddlewareTrait.php +++ b/src/Modifiers/HostMiddlewareTrait.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ diff --git a/src/Modifiers/HostToAscii.php b/src/Modifiers/HostToAscii.php index 13cdaf23..3bb09dc6 100644 --- a/src/Modifiers/HostToAscii.php +++ b/src/Modifiers/HostToAscii.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/HostToUnicode.php b/src/Modifiers/HostToUnicode.php index 65f6e85c..0cf6b2ee 100644 --- a/src/Modifiers/HostToUnicode.php +++ b/src/Modifiers/HostToUnicode.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/KsortQuery.php b/src/Modifiers/KsortQuery.php index 220134ad..f31dc945 100644 --- a/src/Modifiers/KsortQuery.php +++ b/src/Modifiers/KsortQuery.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/MergeQuery.php b/src/Modifiers/MergeQuery.php index 90d73876..688f4754 100644 --- a/src/Modifiers/MergeQuery.php +++ b/src/Modifiers/MergeQuery.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Normalize.php b/src/Modifiers/Normalize.php index f828f8af..803789d6 100644 --- a/src/Modifiers/Normalize.php +++ b/src/Modifiers/Normalize.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/PathMiddlewareTrait.php b/src/Modifiers/PathMiddlewareTrait.php index 19eb3f30..d2ecb521 100644 --- a/src/Modifiers/PathMiddlewareTrait.php +++ b/src/Modifiers/PathMiddlewareTrait.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ diff --git a/src/Modifiers/Pipeline.php b/src/Modifiers/Pipeline.php index ed7b4924..4e4e18cf 100644 --- a/src/Modifiers/Pipeline.php +++ b/src/Modifiers/Pipeline.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/PrependLabel.php b/src/Modifiers/PrependLabel.php index 21934db3..ff8e173e 100644 --- a/src/Modifiers/PrependLabel.php +++ b/src/Modifiers/PrependLabel.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/PrependSegment.php b/src/Modifiers/PrependSegment.php index 1483f1dc..2c2158e2 100644 --- a/src/Modifiers/PrependSegment.php +++ b/src/Modifiers/PrependSegment.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/PublicSuffix.php b/src/Modifiers/PublicSuffix.php new file mode 100644 index 00000000..eeb49a33 --- /dev/null +++ b/src/Modifiers/PublicSuffix.php @@ -0,0 +1,73 @@ + + * @copyright 2016 Ignace Nyamagana Butera + * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) + * @version 1.4.0 + * @link https://github.com/thephpleague/uri-manipulations + */ +declare(strict_types=1); + +namespace League\Uri\Modifiers; + +use League\Uri\PublicSuffix\Rules; + +/** + * Modify the public suffix part of the URI host + * + * @package League\Uri + * @subpackage League\Uri\Modifiers + * @author Ignace Nyamagana Butera + * @since 1.4.0 + */ +class PublicSuffix implements UriMiddlewareInterface +{ + use HostMiddlewareTrait; + use UriMiddlewareTrait; + + /** + * A Host object + * + * @var string + */ + protected $label; + + /** + * @var Rules|null + */ + protected $resolver; + + /** + * New instance + * + * @param string $label the data to be used + * @param null|Rules $resolver + * + */ + public function __construct(string $label, Rules $resolver = null) + { + $this->resolver = $resolver; + $label = $this->filterHost($label, $this->resolver); + if ($label->isAbsolute()) { + throw new Exception('The submitted public suffix can not be a fully qualified domaine name'); + } + + $this->label = (string) $label; + } + + /** + * Modify a URI part + * + * @param string $str the URI part string representation + * + * @return string the modified URI part string representation + */ + protected function modifyHost(string $str): string + { + return (string) $this->filterHost($str, $this->resolver)->withPublicSuffix($this->label); + } +} diff --git a/src/Modifiers/QueryMiddlewareTrait.php b/src/Modifiers/QueryMiddlewareTrait.php index 3c7aeeb0..52246a6f 100644 --- a/src/Modifiers/QueryMiddlewareTrait.php +++ b/src/Modifiers/QueryMiddlewareTrait.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ diff --git a/src/Modifiers/RegisterableDomain.php b/src/Modifiers/RegisterableDomain.php index 717838a1..716e6074 100644 --- a/src/Modifiers/RegisterableDomain.php +++ b/src/Modifiers/RegisterableDomain.php @@ -7,13 +7,15 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); namespace League\Uri\Modifiers; +use League\Uri\PublicSuffix\Rules; + /** * Modify the registerable domain part of the URI host * @@ -34,15 +36,22 @@ class RegisterableDomain implements UriMiddlewareInterface */ protected $label; + /** + * @var Rules|null + */ + protected $resolver; + /** * New instance * - * @param string $label the data to be used + * @param string $label the data to be used + * @param null|Rules $resolver * */ - public function __construct(string $label) + public function __construct(string $label, Rules $resolver = null) { - $label = $this->filterHost($label); + $this->resolver = $resolver; + $label = $this->filterHost($label, $this->resolver); if ($label->isAbsolute()) { throw new Exception('The submitted registerable domain can not be a fully qualified domaine name'); } @@ -59,6 +68,6 @@ public function __construct(string $label) */ protected function modifyHost(string $str): string { - return (string) $this->filterHost($str)->withRegisterableDomain($this->label); + return (string) $this->filterHost($str, $this->resolver)->withRegisterableDomain($this->label); } } diff --git a/src/Modifiers/RemoveBasePath.php b/src/Modifiers/RemoveBasePath.php index 6be3d062..28da261f 100644 --- a/src/Modifiers/RemoveBasePath.php +++ b/src/Modifiers/RemoveBasePath.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveDotSegments.php b/src/Modifiers/RemoveDotSegments.php index 268b2035..fde4455d 100644 --- a/src/Modifiers/RemoveDotSegments.php +++ b/src/Modifiers/RemoveDotSegments.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveEmptySegments.php b/src/Modifiers/RemoveEmptySegments.php index 049ffd42..d6e0b28d 100644 --- a/src/Modifiers/RemoveEmptySegments.php +++ b/src/Modifiers/RemoveEmptySegments.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveLabels.php b/src/Modifiers/RemoveLabels.php index 9ad8b7d8..b3e6dabb 100644 --- a/src/Modifiers/RemoveLabels.php +++ b/src/Modifiers/RemoveLabels.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveLeadingSlash.php b/src/Modifiers/RemoveLeadingSlash.php index 57a82145..c8ab41d0 100644 --- a/src/Modifiers/RemoveLeadingSlash.php +++ b/src/Modifiers/RemoveLeadingSlash.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveQueryKeys.php b/src/Modifiers/RemoveQueryKeys.php index fa1a7c65..a23ee37d 100644 --- a/src/Modifiers/RemoveQueryKeys.php +++ b/src/Modifiers/RemoveQueryKeys.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveQueryParams.php b/src/Modifiers/RemoveQueryParams.php index 0ecf0a8f..60cdf70c 100644 --- a/src/Modifiers/RemoveQueryParams.php +++ b/src/Modifiers/RemoveQueryParams.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveRootLabel.php b/src/Modifiers/RemoveRootLabel.php index 5380e6ae..0999fdb5 100644 --- a/src/Modifiers/RemoveRootLabel.php +++ b/src/Modifiers/RemoveRootLabel.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveSegments.php b/src/Modifiers/RemoveSegments.php index a66d008b..a1de4fa9 100644 --- a/src/Modifiers/RemoveSegments.php +++ b/src/Modifiers/RemoveSegments.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveTrailingSlash.php b/src/Modifiers/RemoveTrailingSlash.php index 97e14261..df5098f7 100644 --- a/src/Modifiers/RemoveTrailingSlash.php +++ b/src/Modifiers/RemoveTrailingSlash.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/RemoveZoneIdentifier.php b/src/Modifiers/RemoveZoneIdentifier.php index 8197ba28..6981ba02 100644 --- a/src/Modifiers/RemoveZoneIdentifier.php +++ b/src/Modifiers/RemoveZoneIdentifier.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/ReplaceLabel.php b/src/Modifiers/ReplaceLabel.php index 76fcb874..6319319e 100644 --- a/src/Modifiers/ReplaceLabel.php +++ b/src/Modifiers/ReplaceLabel.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/ReplaceSegment.php b/src/Modifiers/ReplaceSegment.php index 79def1bb..ccf8ee51 100644 --- a/src/Modifiers/ReplaceSegment.php +++ b/src/Modifiers/ReplaceSegment.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Resolve.php b/src/Modifiers/Resolve.php index 84be2f6c..6597e91d 100644 --- a/src/Modifiers/Resolve.php +++ b/src/Modifiers/Resolve.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); diff --git a/src/Modifiers/Subdomain.php b/src/Modifiers/Subdomain.php index 158f12b2..efb56e28 100644 --- a/src/Modifiers/Subdomain.php +++ b/src/Modifiers/Subdomain.php @@ -7,13 +7,15 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); namespace League\Uri\Modifiers; +use League\Uri\PublicSuffix\Rules; + /** * Modify the subdomains of the URI host * @@ -34,15 +36,22 @@ class Subdomain implements UriMiddlewareInterface */ protected $label; + /** + * @var Rules|null + */ + protected $resolver; + /** * New instance * - * @param string $label the data to be used + * @param string $label the data to be used + * @param null|Rules $resolver * */ - public function __construct(string $label) + public function __construct(string $label, Rules $resolver = null) { - $label = $this->filterHost($label); + $this->resolver = $resolver; + $label = $this->filterHost($label, $this->resolver); if ($label->isAbsolute()) { throw new Exception('The submitted subdomain can not be a fully qualified domaine name'); } @@ -59,6 +68,6 @@ public function __construct(string $label) */ protected function modifyHost(string $str): string { - return (string) $this->filterHost($str)->withSubdomain($this->label); + return (string) $this->filterHost($str, $this->resolver)->withSubdomain($this->label); } } diff --git a/src/Modifiers/UriMiddlewareInterface.php b/src/Modifiers/UriMiddlewareInterface.php index c63af4f4..87328559 100644 --- a/src/Modifiers/UriMiddlewareInterface.php +++ b/src/Modifiers/UriMiddlewareInterface.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ diff --git a/src/Modifiers/UriMiddlewareTrait.php b/src/Modifiers/UriMiddlewareTrait.php index b5e54eaa..f1458587 100644 --- a/src/Modifiers/UriMiddlewareTrait.php +++ b/src/Modifiers/UriMiddlewareTrait.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2016 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ @@ -19,6 +19,7 @@ use League\Uri\Components\Path; use League\Uri\Components\Query; use League\Uri\Interfaces\Uri; +use League\Uri\PublicSuffix\Rules; use Psr\Http\Message\UriInterface; /** @@ -133,13 +134,14 @@ protected function filterString(string $str): string /** * Filter and validate the host string * - * @param string $label the data to validate + * @param string $label the data to validate + * @param null|Rules $resolver * * @return Host */ - protected function filterHost(string $label): Host + protected function filterHost(string $label, Rules $resolver = null): Host { - return new Host($this->filterString($label)); + return new Host($this->filterString($label), $resolver); } /** diff --git a/src/functions.php b/src/functions.php index f9893243..3a05ca0e 100644 --- a/src/functions.php +++ b/src/functions.php @@ -7,7 +7,7 @@ * @author Ignace Nyamagana Butera * @copyright 2017 Ignace Nyamagana Butera * @license https://github.com/thephpleague/uri-manipulations/blob/master/LICENSE (MIT License) - * @version 1.3.0 + * @version 1.4.0 * @link https://github.com/thephpleague/uri-manipulations */ declare(strict_types=1); @@ -15,6 +15,7 @@ namespace League\Uri; use League\Uri\Interfaces\Uri; +use League\Uri\PublicSuffix\Rules; use Psr\Http\Message\UriInterface; /** @@ -607,6 +608,22 @@ function replace_label($uri, int $offset, string $host) return (new Modifiers\ReplaceLabel($offset, $host))->process($uri); } +/** + * Replace the host public suffix part + * + * @see Modifiers\PublicSuffix::modifyHost() + * + * @param Uri|UriInterface $uri + * @param string $host + * @param null|Rules $resolver + * + * @return Uri|UriInterface + */ +function replace_publicsuffix($uri, string $host, Rules $resolver = null) +{ + return (new Modifiers\PublicSuffix($host, $resolver))->process($uri); +} + /** * Replace the host registrabledomain * @@ -614,12 +631,13 @@ function replace_label($uri, int $offset, string $host) * * @param Uri|UriInterface $uri * @param string $host + * @param null|Rules $resolver * * @return Uri|UriInterface */ -function replace_registrabledomain($uri, string $host) +function replace_registrabledomain($uri, string $host, Rules $resolver = null) { - return (new Modifiers\RegisterableDomain($host))->process($uri); + return (new Modifiers\RegisterableDomain($host, $resolver))->process($uri); } /** @@ -645,12 +663,13 @@ function replace_segment($uri, int $offset, string $path) * * @param Uri|UriInterface $uri * @param string $host + * @param null|Rules $resolver * * @return Uri|UriInterface */ -function replace_subdomain($uri, string $host) +function replace_subdomain($uri, string $host, Rules $resolver = null) { - return (new Modifiers\Subdomain($host))->process($uri); + return (new Modifiers\Subdomain($host, $resolver))->process($uri); } /** diff --git a/tests/HostModifierTest.php b/tests/HostModifierTest.php index d1871882..e71bdb78 100644 --- a/tests/HostModifierTest.php +++ b/tests/HostModifierTest.php @@ -197,6 +197,15 @@ public function testRegisterableDomain() $this->assertSame('www.ulb.ac.be', (string) Uri\replace_registrabledomain($this->uri, 'ulb.ac.be')->getHost()); } + /** + * @covers \League\Uri\replace_publicsuffix + * @covers \League\Uri\Modifiers\PublicSuffix + */ + public function testPublicSuffix() + { + $this->assertSame('www.example.fr', (string) Uri\replace_publicsuffix($this->uri, 'fr')->getHost()); + } + /** * @covers \League\Uri\add_root_label * @covers \League\Uri\Modifiers\AddRootLabel @@ -215,6 +224,16 @@ public function testRemoveRootLabel() $this->assertSame('www.example.com', (string) Uri\remove_root_label($this->uri)->getHost()); } + /** + * @covers \League\Uri\replace_publicsuffix + * @covers \League\Uri\Modifiers\PublicSuffix + */ + public function testPublicSuffixFailed() + { + $this->expectException(InvalidArgumentException::class); + Uri\replace_publicsuffix($this->uri, 'example.com.'); + } + /** * @covers \League\Uri\replace_registrabledomain * @covers \League\Uri\Modifiers\RegisterableDomain