diff --git a/CHANGELOG.md b/CHANGELOG.md index f9c9f44..2939b03 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 36dc64e..a000604 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 91690ab..9491db3 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 f9a459e..afa5ed5 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 2d42998..23ffd8d 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 56a272f..ddba1bc 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 566a7ee..b2d0523 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 7f9892f..6097495 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 1a85af4..09d3992 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 2292ae2..faaca29 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 6943805..76de14d 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 abaa164..f8c89d3 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 555fec5..a4827a1 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 cb1214f..98c3b4a 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 4b00e64..8f2634c 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 06a1ac4..aa7231b 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 fb4081a..01a8fa6 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 cfa59ab..ea2ffb1 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 e8cd2a8..3794b3a 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 1ade4cb..0afc6bf 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 13cdaf2..3bb09dc 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 65f6e85..0cf6b2e 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 220134a..f31dc94 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 90d7387..688f475 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 f828f8a..803789d 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 19eb3f3..d2ecb52 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 ed7b492..4e4e18c 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 21934db..ff8e173 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 1483f1d..2c2158e 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 0000000..eeb49a3 --- /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 3c7aeeb..52246a6 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 717838a..716e607 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 6be3d06..28da261 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 268b203..fde4455 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 049ffd4..d6e0b28 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 9ad8b7d..b3e6dab 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 57a8214..c8ab41d 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 fa1a7c6..a23ee37 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 0ecf0a8..60cdf70 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 5380e6a..0999fdb 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 a66d008..a1de4fa 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 97e1426..df5098f 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 8197ba2..6981ba0 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 76fcb87..6319319 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 79def1b..ccf8ee5 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 84be2f6..6597e91 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 158f12b..efb56e2 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 c63af4f..8732855 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 b5e54ea..f145858 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 f989324..3a05ca0 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 d187188..e71bdb7 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