From b79ef63f5c4cca09568b2272ff381711b5945842 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:23:55 +0500 Subject: [PATCH 1/8] csf --- src/Component/ComponentInterface.php | 12 +- src/Component/Fragment.php | 73 +- src/Component/Host.php | 73 +- src/Component/Pass.php | 73 +- src/Component/Path.php | 73 +- src/Component/Port.php | 79 +-- src/Component/Query.php | 73 +- src/Component/Scheme.php | 77 +- src/Component/User.php | 73 +- src/Component/UserInfo.php | 69 +- .../InvalidUriComponentException.php | 3 +- src/Exception/InvalidUriException.php | 3 +- src/Uri.php | 665 ++++++++---------- src/UriFactory.php | 14 +- src/UriParser.php | 377 +++++----- 15 files changed, 833 insertions(+), 904 deletions(-) diff --git a/src/Component/ComponentInterface.php b/src/Component/ComponentInterface.php index 8113714..9a76b9d 100644 --- a/src/Component/ComponentInterface.php +++ b/src/Component/ComponentInterface.php @@ -17,10 +17,10 @@ interface ComponentInterface { - /** - * Presents the component value - * - * @return mixed - */ - public function present(); + /** + * Presents the component value + * + * @return mixed + */ + public function present(); } diff --git a/src/Component/Fragment.php b/src/Component/Fragment.php index 5d561a8..2b080b4 100644 --- a/src/Component/Fragment.php +++ b/src/Component/Fragment.php @@ -24,47 +24,44 @@ class Fragment implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "fragment" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "fragment" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Component/Host.php b/src/Component/Host.php index 05b9cba..c78c374 100644 --- a/src/Component/Host.php +++ b/src/Component/Host.php @@ -24,47 +24,44 @@ class Host implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "host" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "host" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return \strtolower($this->value); - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return \strtolower($this->value); + } } diff --git a/src/Component/Pass.php b/src/Component/Pass.php index 5744d81..c84c3fb 100644 --- a/src/Component/Pass.php +++ b/src/Component/Pass.php @@ -24,47 +24,44 @@ class Pass implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "pass" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "pass" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Component/Path.php b/src/Component/Path.php index 8345661..a622325 100644 --- a/src/Component/Path.php +++ b/src/Component/Path.php @@ -24,47 +24,44 @@ class Path implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "path" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "path" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Component/Port.php b/src/Component/Port.php index d85e254..4d1519d 100644 --- a/src/Component/Port.php +++ b/src/Component/Port.php @@ -24,48 +24,47 @@ class Port implements ComponentInterface { - /** - * The component value - * - * @var null|int - */ - protected $value; + /** + * The component value + * + * @var null|int + */ + protected $value; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - $min = 1; - $max = 2 ** 16; + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + $min = 1; + $max = 2 ** 16; - if (null === $value) - { - return; - } - else if (! \is_int($value)) - { - throw new InvalidUriComponentException('URI component "port" must be an integer'); - } - else if (! ($value >= $min && $value <= $max)) - { - throw new InvalidUriComponentException('Invalid URI component "port"'); - } + if (null === $value) { + return; + } - $this->value = $value; - } + if (! \is_int($value)) { + throw new InvalidUriComponentException('URI component "port" must be an integer'); + } - /** - * {@inheritDoc} - * - * @return null|int - */ - public function present() : ?int - { - return $this->value; - } + if (! ($value >= $min && $value <= $max)) { + throw new InvalidUriComponentException('Invalid URI component "port"'); + } + + $this->value = $value; + } + + /** + * {@inheritDoc} + * + * @return null|int + */ + public function present() : ?int + { + return $this->value; + } } diff --git a/src/Component/Query.php b/src/Component/Query.php index 26914c8..4a3865b 100644 --- a/src/Component/Query.php +++ b/src/Component/Query.php @@ -24,47 +24,44 @@ class Query implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "query" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "query" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=\:@\/\?]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Component/Scheme.php b/src/Component/Scheme.php index 66582fc..0d88db4 100644 --- a/src/Component/Scheme.php +++ b/src/Component/Scheme.php @@ -24,47 +24,46 @@ class Scheme implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - $regex = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + $regex = '/^(?:[A-Za-z][0-9A-Za-z\+\-\.]*)?$/'; - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "scheme" must be a string'); - } - else if (! \preg_match($regex, $value)) - { - throw new InvalidUriComponentException('Invalid URI component "scheme"'); - } + if ('' === $value) { + return; + } - $this->value = $value; - } + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "scheme" must be a string'); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return \strtolower($this->value); - } + if (! \preg_match($regex, $value)) { + throw new InvalidUriComponentException('Invalid URI component "scheme"'); + } + + $this->value = $value; + } + + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return \strtolower($this->value); + } } diff --git a/src/Component/User.php b/src/Component/User.php index 18f7292..9710525 100644 --- a/src/Component/User.php +++ b/src/Component/User.php @@ -24,47 +24,44 @@ class User implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; + /** + * The component value + * + * @var string + */ + protected $value = ''; - /** - * Constructor of the class - * - * @param mixed $value - * - * @throws InvalidUriComponentException - */ - public function __construct($value) - { - if ('' === $value) - { - return; - } - else if (! \is_string($value)) - { - throw new InvalidUriComponentException('URI component "user" must be a string'); - } + /** + * Constructor of the class + * + * @param mixed $value + * + * @throws InvalidUriComponentException + */ + public function __construct($value) + { + if ('' === $value) { + return; + } - $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; + if (! \is_string($value)) { + throw new InvalidUriComponentException('URI component "user" must be a string'); + } - $this->value = \preg_replace_callback($regex, function($match) - { - return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + $regex = '/(?:(?:%[0-9A-Fa-f]{2}|[0-9A-Za-z\-\._~\!\$&\'\(\)\*\+,;\=]+)|(.?))/u'; - }, $value); - } + $this->value = \preg_replace_callback($regex, function ($match) { + return isset($match[1]) ? \rawurlencode($match[1]) : $match[0]; + }, $value); + } - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Component/UserInfo.php b/src/Component/UserInfo.php index 7d9a372..336c5b0 100644 --- a/src/Component/UserInfo.php +++ b/src/Component/UserInfo.php @@ -19,40 +19,37 @@ class UserInfo implements ComponentInterface { - /** - * The component value - * - * @var string - */ - protected $value = ''; - - /** - * Constructor of the class - * - * @param mixed $user - * @param mixed $pass - */ - public function __construct($user, $pass = null) - { - $user = new User($user); - - $this->value = $user->present(); - - if (! (null === $pass)) - { - $pass = new Pass($pass); - - $this->value .= ':' . $pass->present(); - } - } - - /** - * {@inheritDoc} - * - * @return string - */ - public function present() : string - { - return $this->value; - } + /** + * The component value + * + * @var string + */ + protected $value = ''; + + /** + * Constructor of the class + * + * @param mixed $user + * @param mixed $pass + */ + public function __construct($user, $pass = null) + { + $user = new User($user); + $this->value = $user->present(); + + if (! (null === $pass)) { + $pass = new Pass($pass); + $this->value .= ':' . $pass->present(); + } + } + + /** + * {@inheritDoc} + * + * @return string + */ + public function present() : string + { + return $this->value; + } } diff --git a/src/Exception/InvalidUriComponentException.php b/src/Exception/InvalidUriComponentException.php index 5d717ab..135b89d 100644 --- a/src/Exception/InvalidUriComponentException.php +++ b/src/Exception/InvalidUriComponentException.php @@ -20,4 +20,5 @@ * InvalidUriComponentException */ class InvalidUriComponentException extends InvalidArgumentException -{} +{ +} diff --git a/src/Exception/InvalidUriException.php b/src/Exception/InvalidUriException.php index 8760be2..fb0a9c8 100644 --- a/src/Exception/InvalidUriException.php +++ b/src/Exception/InvalidUriException.php @@ -20,4 +20,5 @@ * InvalidUriException */ class InvalidUriException extends InvalidArgumentException -{} +{ +} diff --git a/src/Uri.php b/src/Uri.php index 680e484..2d6f992 100644 --- a/src/Uri.php +++ b/src/Uri.php @@ -37,360 +37,313 @@ class Uri implements UriInterface { - /** - * The URI component "scheme" - * - * @var string - */ - protected $scheme = ''; - - /** - * The URI component "userinfo" - * - * @var string - */ - protected $userinfo = ''; - - /** - * The URI component "host" - * - * @var string - */ - protected $host = ''; - - /** - * The URI component "port" - * - * @var null|int - */ - protected $port; - - /** - * The URI component "path" - * - * @var string - */ - protected $path = ''; - - /** - * The URI component "query" - * - * @var string - */ - protected $query = ''; - - /** - * The URI component "fragment" - * - * @var string - */ - protected $fragment = ''; - - /** - * Constructor of the class - * - * @param mixed $uri - */ - public function __construct($uri = '') - { - // resource savings... - if ('' === $uri) { - return; - } - - $components = new UriParser($uri); - - $this->scheme = $components - ->getScheme() - ->present(); - - $this->userinfo = $components - ->getUserInfo() - ->present(); - - $this->host = $components - ->getHost() - ->present(); - - $this->port = $components - ->getPort() - ->present(); - - $this->path = $components - ->getPath() - ->present(); - - $this->query = $components - ->getQuery() - ->present(); - - $this->fragment = $components - ->getFragment() - ->present(); - } - - /** - * {@inheritDoc} - */ - public function withScheme($scheme) : UriInterface - { - $clone = clone $this; - - $component = new Scheme($scheme); - - $clone->scheme = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withUserInfo($user, $pass = null) : UriInterface - { - $clone = clone $this; - - $component = new UserInfo($user, $pass); - - $clone->userinfo = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withHost($host) : UriInterface - { - $clone = clone $this; - - $component = new Host($host); - - $clone->host = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withPort($port) : UriInterface - { - $clone = clone $this; - - $component = new Port($port); - - $clone->port = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withPath($path) : UriInterface - { - $clone = clone $this; - - $component = new Path($path); - - $clone->path = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withQuery($query) : UriInterface - { - $clone = clone $this; - - $component = new Query($query); - - $clone->query = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function withFragment($fragment) : UriInterface - { - $clone = clone $this; - - $component = new Fragment($fragment); - - $clone->fragment = $component->present(); - - return $clone; - } - - /** - * {@inheritDoc} - */ - public function getScheme() : string - { - return $this->scheme; - } - - /** - * {@inheritDoc} - */ - public function getUserInfo() : string - { - return $this->userinfo; - } - - /** - * {@inheritDoc} - */ - public function getHost() : string - { - return $this->host; - } - - /** - * {@inheritDoc} - */ - public function getPort() : ?int - { - $scheme = $this->getScheme(); - - // The 80 is the default port number for the HTTP protocol. - if (80 === $this->port && 'http' === $scheme) { - return null; - } - - // The 443 is the default port number for the HTTPS protocol. - if (443 === $this->port && 'https' === $scheme) { - return null; - } - - return $this->port; - } - - /** - * Gets standard port number associated with the URI scheme - * - * [!] It's not PSR-7 method. - * - * @return null|int - */ - public function getStandardPort() : ?int - { - $scheme = $this->getScheme(); - - $servicePort = getservbyname($scheme, 'tcp'); - if (false !== $servicePort) { - return $servicePort; - } - - $servicePort = getservbyname($scheme, 'udp'); - if (false !== $servicePort) { - return $servicePort; - } - - return null; - } - - /** - * {@inheritDoc} - */ - public function getPath() : string - { - return $this->path; - } - - /** - * {@inheritDoc} - */ - public function getQuery() : string - { - return $this->query; - } - - /** - * {@inheritDoc} - */ - public function getFragment() : string - { - return $this->fragment; - } - - /** - * {@inheritDoc} - */ - public function getAuthority() : string - { - $authority = $this->getHost(); - - // Host is the basic subcomponent. - if ('' === $authority) - { - return ''; - } - - $userinfo = $this->getUserInfo(); - - if (! ('' === $userinfo)) - { - $authority = $userinfo . '@' . $authority; - } - - $port = $this->getPort(); - - if (! (null === $port)) - { - $authority = $authority . ':' . $port; - } - - return $authority; - } - - /** - * {@inheritDoc} - */ - public function __toString() - { - $uri = ''; - - $scheme = $this->getScheme(); - - if (! ('' === $scheme)) - { - $uri .= $scheme . ':'; - } - - $authority = $this->getAuthority(); - - if (! ('' === $authority)) - { - $uri .= '//' . $authority; - } - - $path = $this->getPath(); - - if (! ('' === $path)) - { - $uri .= $path; - } - - $query = $this->getQuery(); - - if (! ('' === $query)) - { - $uri .= '?' . $query; - } - - $fragment = $this->getFragment(); - - if (! ('' === $fragment)) - { - $uri .= '#' . $fragment; - } - - return $uri; - } + /** + * The URI component "scheme" + * + * @var string + */ + protected $scheme = ''; + + /** + * The URI component "userinfo" + * + * @var string + */ + protected $userinfo = ''; + + /** + * The URI component "host" + * + * @var string + */ + protected $host = ''; + + /** + * The URI component "port" + * + * @var null|int + */ + protected $port; + + /** + * The URI component "path" + * + * @var string + */ + protected $path = ''; + + /** + * The URI component "query" + * + * @var string + */ + protected $query = ''; + + /** + * The URI component "fragment" + * + * @var string + */ + protected $fragment = ''; + + /** + * Constructor of the class + * + * @param mixed $uri + */ + public function __construct($uri = '') + { + // resource savings... + if ('' === $uri) { + return; + } + + $components = new UriParser($uri); + + $this->scheme = $components->getScheme()->present(); + $this->userinfo = $components->getUserInfo()->present(); + $this->host = $components->getHost()->present(); + $this->port = $components->getPort()->present(); + $this->path = $components->getPath()->present(); + $this->query = $components->getQuery()->present(); + $this->fragment = $components->getFragment()->present(); + } + + /** + * {@inheritDoc} + */ + public function withScheme($scheme) : UriInterface + { + $clone = clone $this; + $component = new Scheme($scheme); + $clone->scheme = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withUserInfo($user, $pass = null) : UriInterface + { + $clone = clone $this; + $component = new UserInfo($user, $pass); + $clone->userinfo = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withHost($host) : UriInterface + { + $clone = clone $this; + $component = new Host($host); + $clone->host = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withPort($port) : UriInterface + { + $clone = clone $this; + $component = new Port($port); + $clone->port = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withPath($path) : UriInterface + { + $clone = clone $this; + $component = new Path($path); + $clone->path = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withQuery($query) : UriInterface + { + $clone = clone $this; + $component = new Query($query); + $clone->query = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function withFragment($fragment) : UriInterface + { + $clone = clone $this; + $component = new Fragment($fragment); + $clone->fragment = $component->present(); + + return $clone; + } + + /** + * {@inheritDoc} + */ + public function getScheme() : string + { + return $this->scheme; + } + + /** + * {@inheritDoc} + */ + public function getUserInfo() : string + { + return $this->userinfo; + } + + /** + * {@inheritDoc} + */ + public function getHost() : string + { + return $this->host; + } + + /** + * {@inheritDoc} + */ + public function getPort() : ?int + { + $scheme = $this->getScheme(); + + // The 80 is the default port number for the HTTP protocol. + if (80 === $this->port && 'http' === $scheme) { + return null; + } + + // The 443 is the default port number for the HTTPS protocol. + if (443 === $this->port && 'https' === $scheme) { + return null; + } + + return $this->port; + } + + /** + * Gets standard port number associated with the URI scheme + * + * [!] It's not PSR-7 method. + * + * @return null|int + * + * @codeCoverageIgnore + */ + public function getStandardPort() : ?int + { + $scheme = $this->getScheme(); + + $servicePort = getservbyname($scheme, 'tcp'); + if (false !== $servicePort) { + return $servicePort; + } + + $servicePort = getservbyname($scheme, 'udp'); + if (false !== $servicePort) { + return $servicePort; + } + + return null; + } + + /** + * {@inheritDoc} + */ + public function getPath() : string + { + return $this->path; + } + + /** + * {@inheritDoc} + */ + public function getQuery() : string + { + return $this->query; + } + + /** + * {@inheritDoc} + */ + public function getFragment() : string + { + return $this->fragment; + } + + /** + * {@inheritDoc} + */ + public function getAuthority() : string + { + $authority = $this->getHost(); + + // Host is the basic subcomponent. + if ('' === $authority) { + return ''; + } + + $userinfo = $this->getUserInfo(); + if (! ('' === $userinfo)) { + $authority = $userinfo . '@' . $authority; + } + + $port = $this->getPort(); + if (! (null === $port)) { + $authority = $authority . ':' . $port; + } + + return $authority; + } + + /** + * {@inheritDoc} + */ + public function __toString() + { + $uri = ''; + + $scheme = $this->getScheme(); + if (! ('' === $scheme)) { + $uri .= $scheme . ':'; + } + + $authority = $this->getAuthority(); + if (! ('' === $authority)) { + $uri .= '//' . $authority; + } + + $path = $this->getPath(); + if (! ('' === $path)) { + $uri .= $path; + } + + $query = $this->getQuery(); + if (! ('' === $query)) { + $uri .= '?' . $query; + } + + $fragment = $this->getFragment(); + if (! ('' === $fragment)) { + $uri .= '#' . $fragment; + } + + return $uri; + } } diff --git a/src/UriFactory.php b/src/UriFactory.php index b954bd0..8a1e8ec 100644 --- a/src/UriFactory.php +++ b/src/UriFactory.php @@ -25,11 +25,11 @@ class UriFactory implements UriFactoryInterface { - /** - * {@inheritDoc} - */ - public function createUri(string $uri = '') : UriInterface - { - return new Uri($uri); - } + /** + * {@inheritDoc} + */ + public function createUri(string $uri = '') : UriInterface + { + return new Uri($uri); + } } diff --git a/src/UriParser.php b/src/UriParser.php index 97ed46b..7ace2c6 100644 --- a/src/UriParser.php +++ b/src/UriParser.php @@ -32,194 +32,191 @@ class UriParser { - /** - * The parsed URI component "scheme" - * - * @var ComponentInterface - */ - protected $scheme; - - /** - * The parsed URI component "user" - * - * @var ComponentInterface - */ - protected $user; - - /** - * The parsed URI component "pass" - * - * @var ComponentInterface - */ - protected $pass; - - /** - * The parsed URI component "host" - * - * @var ComponentInterface - */ - protected $host; - - /** - * The parsed URI component "port" - * - * @var ComponentInterface - */ - protected $port; - - /** - * The parsed URI component "path" - * - * @var ComponentInterface - */ - protected $path; - - /** - * The parsed URI component "query" - * - * @var ComponentInterface - */ - protected $query; - - /** - * The parsed URI component "fragment" - * - * @var ComponentInterface - */ - protected $fragment; - - /** - * The parsed URI component "userinfo" - * - * @var ComponentInterface - */ - protected $userinfo; - - /** - * Constructor of the class - * - * @param mixed $uri - * - * @throws InvalidUriException - * - * @link http://php.net/manual/en/function.parse-url.php - */ - public function __construct($uri) - { - if (! \is_string($uri)) - { - throw new InvalidUriException('URI must be a string'); - } - - $components = \parse_url($uri); - - if (false === $components) - { - throw new InvalidUriException('Unable to parse URI'); - } - - $this->scheme = new Scheme($components['scheme'] ?? ''); - $this->user = new User($components['user'] ?? ''); - $this->pass = new Pass($components['pass'] ?? ''); - $this->host = new Host($components['host'] ?? ''); - $this->port = new Port($components['port'] ?? null); - $this->path = new Path($components['path'] ?? ''); - $this->query = new Query($components['query'] ?? ''); - $this->fragment = new Fragment($components['fragment'] ?? ''); - - $this->userinfo = new UserInfo( - $components['user'] ?? '', - $components['pass'] ?? null - ); - } - - /** - * Gets the parsed URI component "scheme" - * - * @return ComponentInterface - */ - public function getScheme() : ComponentInterface - { - return $this->scheme; - } - - /** - * Gets the parsed URI component "user" - * - * @return ComponentInterface - */ - public function getUser() : ComponentInterface - { - return $this->user; - } - - /** - * Gets the parsed URI component "pass" - * - * @return ComponentInterface - */ - public function getPass() : ComponentInterface - { - return $this->pass; - } - - /** - * Gets the parsed URI component "host" - * - * @return ComponentInterface - */ - public function getHost() : ComponentInterface - { - return $this->host; - } - - /** - * Gets the parsed URI component "port" - * - * @return ComponentInterface - */ - public function getPort() : ComponentInterface - { - return $this->port; - } - - /** - * Gets the parsed URI component "path" - * - * @return ComponentInterface - */ - public function getPath() : ComponentInterface - { - return $this->path; - } - - /** - * Gets the parsed URI component "query" - * - * @return ComponentInterface - */ - public function getQuery() : ComponentInterface - { - return $this->query; - } - - /** - * Gets the parsed URI component "fragment" - * - * @return ComponentInterface - */ - public function getFragment() : ComponentInterface - { - return $this->fragment; - } - - /** - * Gets the parsed URI component "userinfo" - * - * @return ComponentInterface - */ - public function getUserInfo() : ComponentInterface - { - return $this->userinfo; - } + /** + * The parsed URI component "scheme" + * + * @var ComponentInterface + */ + protected $scheme; + + /** + * The parsed URI component "user" + * + * @var ComponentInterface + */ + protected $user; + + /** + * The parsed URI component "pass" + * + * @var ComponentInterface + */ + protected $pass; + + /** + * The parsed URI component "host" + * + * @var ComponentInterface + */ + protected $host; + + /** + * The parsed URI component "port" + * + * @var ComponentInterface + */ + protected $port; + + /** + * The parsed URI component "path" + * + * @var ComponentInterface + */ + protected $path; + + /** + * The parsed URI component "query" + * + * @var ComponentInterface + */ + protected $query; + + /** + * The parsed URI component "fragment" + * + * @var ComponentInterface + */ + protected $fragment; + + /** + * The parsed URI component "userinfo" + * + * @var ComponentInterface + */ + protected $userinfo; + + /** + * Constructor of the class + * + * @param mixed $uri + * + * @throws InvalidUriException + * + * @link http://php.net/manual/en/function.parse-url.php + */ + public function __construct($uri) + { + if (! \is_string($uri)) { + throw new InvalidUriException('URI must be a string'); + } + + $components = \parse_url($uri); + if (false === $components) { + throw new InvalidUriException('Unable to parse URI'); + } + + $this->scheme = new Scheme($components['scheme'] ?? ''); + $this->user = new User($components['user'] ?? ''); + $this->pass = new Pass($components['pass'] ?? ''); + $this->host = new Host($components['host'] ?? ''); + $this->port = new Port($components['port'] ?? null); + $this->path = new Path($components['path'] ?? ''); + $this->query = new Query($components['query'] ?? ''); + $this->fragment = new Fragment($components['fragment'] ?? ''); + + $this->userinfo = new UserInfo( + $components['user'] ?? '', + $components['pass'] ?? null + ); + } + + /** + * Gets the parsed URI component "scheme" + * + * @return ComponentInterface + */ + public function getScheme() : ComponentInterface + { + return $this->scheme; + } + + /** + * Gets the parsed URI component "user" + * + * @return ComponentInterface + */ + public function getUser() : ComponentInterface + { + return $this->user; + } + + /** + * Gets the parsed URI component "pass" + * + * @return ComponentInterface + */ + public function getPass() : ComponentInterface + { + return $this->pass; + } + + /** + * Gets the parsed URI component "host" + * + * @return ComponentInterface + */ + public function getHost() : ComponentInterface + { + return $this->host; + } + + /** + * Gets the parsed URI component "port" + * + * @return ComponentInterface + */ + public function getPort() : ComponentInterface + { + return $this->port; + } + + /** + * Gets the parsed URI component "path" + * + * @return ComponentInterface + */ + public function getPath() : ComponentInterface + { + return $this->path; + } + + /** + * Gets the parsed URI component "query" + * + * @return ComponentInterface + */ + public function getQuery() : ComponentInterface + { + return $this->query; + } + + /** + * Gets the parsed URI component "fragment" + * + * @return ComponentInterface + */ + public function getFragment() : ComponentInterface + { + return $this->fragment; + } + + /** + * Gets the parsed URI component "userinfo" + * + * @return ComponentInterface + */ + public function getUserInfo() : ComponentInterface + { + return $this->userinfo; + } } From d93d31c796067dd475aa000d66d1fc584c44d2fc Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:24:34 +0500 Subject: [PATCH 2/8] sunrise team CS accepted --- phpcs.xml.dist | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 phpcs.xml.dist diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000..be45cac --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,7 @@ + + + + + src + tests + From 977e1d2ff4e6a2cbbbf6e0cf7540c68b67e96973 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:25:00 +0500 Subject: [PATCH 3/8] CS --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 2da7375..27e2667 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,8 +14,5 @@ insert_final_newline = true [*.md] trim_trailing_whitespace = false -[*.php] -indent_style = tab - [*.yml] indent_size = 2 From b6aabf5e548c522b1018843cb3a47e5844d6f143 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:25:20 +0500 Subject: [PATCH 4/8] minor changes --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4c67e86..19aa2e3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Anatoly Fenric +Copyright (c) 2018 Sunrise // PHP Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 01d781d6642fc6e2258ca0aa1ad592858b45fff0 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:25:29 +0500 Subject: [PATCH 5/8] csf --- tests/UriFactoryTest.php | 46 +- tests/UriParserTest.php | 114 ++-- tests/UriTest.php | 1113 +++++++++++++++++++------------------- 3 files changed, 642 insertions(+), 631 deletions(-) diff --git a/tests/UriFactoryTest.php b/tests/UriFactoryTest.php index c7658a5..2c3ebe8 100644 --- a/tests/UriFactoryTest.php +++ b/tests/UriFactoryTest.php @@ -9,37 +9,37 @@ class UriFactoryTest extends TestCase { - public function testConstructor() - { - $factory = new UriFactory(); + public function testConstructor() + { + $factory = new UriFactory(); - $this->assertInstanceOf(UriFactoryInterface::class, $factory); - } + $this->assertInstanceOf(UriFactoryInterface::class, $factory); + } - public function testCreateUri() - { - $uri = (new UriFactory)->createUri('/'); + public function testCreateUri() + { + $uri = (new UriFactory)->createUri('/'); - $this->assertInstanceOf(UriInterface::class, $uri); + $this->assertInstanceOf(UriInterface::class, $uri); - $this->assertEquals('/', $uri->getPath()); - } + $this->assertEquals('/', $uri->getPath()); + } - public function testCreateUriWithoutUri() - { - $uri = (new UriFactory)->createUri(); + public function testCreateUriWithoutUri() + { + $uri = (new UriFactory)->createUri(); - $this->assertInstanceOf(UriInterface::class, $uri); + $this->assertInstanceOf(UriInterface::class, $uri); - $this->assertEquals('', $uri->getPath()); - } + $this->assertEquals('', $uri->getPath()); + } - public function testCreateUriWithEmptyUri() - { - $uri = (new UriFactory)->createUri(''); + public function testCreateUriWithEmptyUri() + { + $uri = (new UriFactory)->createUri(''); - $this->assertInstanceOf(UriInterface::class, $uri); + $this->assertInstanceOf(UriInterface::class, $uri); - $this->assertEquals('', $uri->getPath()); - } + $this->assertEquals('', $uri->getPath()); + } } diff --git a/tests/UriParserTest.php b/tests/UriParserTest.php index eef3162..aa8f175 100644 --- a/tests/UriParserTest.php +++ b/tests/UriParserTest.php @@ -8,83 +8,83 @@ class UriParserTest extends TestCase { - public const TEST_URI = 'scheme://user:pass@host:3000/path?query#fragment'; + public const TEST_URI = 'scheme://user:pass@host:3000/path?query#fragment'; - public function testConstructor() - { - $uri = new UriParser(self::TEST_URI); + public function testConstructor() + { + $uri = new UriParser(self::TEST_URI); - $this->assertInstanceOf(UriParser::class, $uri); - } + $this->assertInstanceOf(UriParser::class, $uri); + } - public function testConstructorWithInvalidString() - { - $this->expectException(InvalidUriException::class); - $this->expectExceptionMessage('URI must be a string'); + public function testConstructorWithInvalidString() + { + $this->expectException(InvalidUriException::class); + $this->expectExceptionMessage('URI must be a string'); - $uri = new UriParser(1234456); - } + $uri = new UriParser(1234456); + } - public function testGetScheme() - { - $uri = new UriParser(self::TEST_URI); + public function testGetScheme() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('scheme', $uri->getScheme()->present()); - } + $this->assertEquals('scheme', $uri->getScheme()->present()); + } - public function testGetUser() - { - $uri = new UriParser(self::TEST_URI); + public function testGetUser() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('user', $uri->getUser()->present()); - } + $this->assertEquals('user', $uri->getUser()->present()); + } - public function testGetPass() - { - $uri = new UriParser(self::TEST_URI); + public function testGetPass() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('pass', $uri->getPass()->present()); - } + $this->assertEquals('pass', $uri->getPass()->present()); + } - public function testGetHost() - { - $uri = new UriParser(self::TEST_URI); + public function testGetHost() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('host', $uri->getHost()->present()); - } + $this->assertEquals('host', $uri->getHost()->present()); + } - public function testGetPort() - { - $uri = new UriParser(self::TEST_URI); + public function testGetPort() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals(3000, $uri->getPort()->present()); - } + $this->assertEquals(3000, $uri->getPort()->present()); + } - public function testGetPath() - { - $uri = new UriParser(self::TEST_URI); + public function testGetPath() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('/path', $uri->getPath()->present()); - } + $this->assertEquals('/path', $uri->getPath()->present()); + } - public function testGetQuery() - { - $uri = new UriParser(self::TEST_URI); + public function testGetQuery() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('query', $uri->getQuery()->present()); - } + $this->assertEquals('query', $uri->getQuery()->present()); + } - public function testGetFragment() - { - $uri = new UriParser(self::TEST_URI); + public function testGetFragment() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('fragment', $uri->getFragment()->present()); - } + $this->assertEquals('fragment', $uri->getFragment()->present()); + } - public function testGetUserInfo() - { - $uri = new UriParser(self::TEST_URI); + public function testGetUserInfo() + { + $uri = new UriParser(self::TEST_URI); - $this->assertEquals('user:pass', $uri->getUserInfo()->present()); - } + $this->assertEquals('user:pass', $uri->getUserInfo()->present()); + } } diff --git a/tests/UriTest.php b/tests/UriTest.php index 3f21e26..efdd445 100644 --- a/tests/UriTest.php +++ b/tests/UriTest.php @@ -10,636 +10,647 @@ class UriTest extends TestCase { - public const TEST_URI = 'scheme://user:pass@host:3000/path?query#fragment'; + public const TEST_URI = 'scheme://user:pass@host:3000/path?query#fragment'; - // Constructor... + // Constructor... - public function testConstructor() - { - $uri = new Uri(self::TEST_URI); + public function testConstructor() + { + $uri = new Uri(self::TEST_URI); - $this->assertInstanceOf(UriInterface::class, $uri); - } + $this->assertInstanceOf(UriInterface::class, $uri); + } - public function testConstructorWithoutUri() - { - $uri = new Uri(); + public function testConstructorWithoutUri() + { + $uri = new Uri(); - $this->assertInstanceOf(UriInterface::class, $uri); - } + $this->assertInstanceOf(UriInterface::class, $uri); + } - public function testConstructorWithEmptyUri() - { - $uri = new Uri(''); + public function testConstructorWithEmptyUri() + { + $uri = new Uri(''); - $this->assertInstanceOf(UriInterface::class, $uri); - } + $this->assertInstanceOf(UriInterface::class, $uri); + } - public function testConstructorWithInvalidUri() - { - $this->expectException(InvalidUriException::class); - $this->expectExceptionMessage('Unable to parse URI'); + public function testConstructorWithInvalidUri() + { + $this->expectException(InvalidUriException::class); + $this->expectExceptionMessage('Unable to parse URI'); - new Uri(':'); - } + new Uri(':'); + } - // Getters... + // Getters... - public function testGetScheme() - { - $uri = new Uri(self::TEST_URI); + public function testGetScheme() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('scheme', $uri->getScheme()); - } + $this->assertEquals('scheme', $uri->getScheme()); + } - public function testGetUserInfo() - { - $uri = new Uri(self::TEST_URI); + public function testGetUserInfo() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('user:pass', $uri->getUserInfo()); - } + $this->assertEquals('user:pass', $uri->getUserInfo()); + } - public function testGetHost() - { - $uri = new Uri(self::TEST_URI); + public function testGetHost() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('host', $uri->getHost()); - } + $this->assertEquals('host', $uri->getHost()); + } - public function testGetPort() - { - $uri = new Uri(self::TEST_URI); + public function testGetPort() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals(3000, $uri->getPort()); - } + $this->assertEquals(3000, $uri->getPort()); + } - public function testGetPath() - { - $uri = new Uri(self::TEST_URI); + public function testGetPath() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('/path', $uri->getPath()); - } + $this->assertEquals('/path', $uri->getPath()); + } - public function testGetQuery() - { - $uri = new Uri(self::TEST_URI); + public function testGetQuery() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('query', $uri->getQuery()); - } + $this->assertEquals('query', $uri->getQuery()); + } - public function testGetFragment() - { - $uri = new Uri(self::TEST_URI); + public function testGetFragment() + { + $uri = new Uri(self::TEST_URI); - $this->assertEquals('fragment', $uri->getFragment()); - } + $this->assertEquals('fragment', $uri->getFragment()); + } - public function testGetStandardPort() : void - { - $uri = new Uri('http://host:3000'); - $this->assertEquals(80, $uri->getStandardPort()); + public function testGetStandardPort() : void + { + $uri = new Uri('http://host:3000'); + $this->assertEquals(80, $uri->getStandardPort()); - $uri = new Uri('https://host:3000'); - $this->assertEquals(443, $uri->getStandardPort()); + $uri = new Uri('https://host:3000'); + $this->assertEquals(443, $uri->getStandardPort()); - $uri = new Uri('ftp://host:3000'); - $this->assertEquals(21, $uri->getStandardPort()); - } + $uri = new Uri('ftp://host:3000'); + $this->assertEquals(21, $uri->getStandardPort()); + } - // Withers... + // Withers... - public function testWithScheme() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withScheme('new-scheme'); + public function testWithScheme() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withScheme('new-scheme'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('scheme', $uri->getScheme()); - $this->assertEquals('new-scheme', $copy->getScheme()); - } + $this->assertEquals('scheme', $uri->getScheme()); + $this->assertEquals('new-scheme', $copy->getScheme()); + } - public function testWithUserInfo() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withUserInfo('new-user', 'new-pass'); + public function testWithUserInfo() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withUserInfo('new-user', 'new-pass'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('user:pass', $uri->getUserInfo()); - $this->assertEquals('new-user:new-pass', $copy->getUserInfo()); - } + $this->assertEquals('user:pass', $uri->getUserInfo()); + $this->assertEquals('new-user:new-pass', $copy->getUserInfo()); + } - public function testWithUserInfoWithoutPass() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withUserInfo('new-user'); + public function testWithUserInfoWithoutPass() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withUserInfo('new-user'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('user:pass', $uri->getUserInfo()); - $this->assertEquals('new-user', $copy->getUserInfo()); - } + $this->assertEquals('user:pass', $uri->getUserInfo()); + $this->assertEquals('new-user', $copy->getUserInfo()); + } - public function testWithHost() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withHost('new-host'); + public function testWithHost() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withHost('new-host'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('host', $uri->getHost()); - $this->assertEquals('new-host', $copy->getHost()); - } + $this->assertEquals('host', $uri->getHost()); + $this->assertEquals('new-host', $copy->getHost()); + } - public function testWithPort() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withPort(80); + public function testWithPort() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withPort(80); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals(3000, $uri->getPort()); - $this->assertEquals(80, $copy->getPort()); - } + $this->assertEquals(3000, $uri->getPort()); + $this->assertEquals(80, $copy->getPort()); + } - public function testWithPath() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withPath('/new-path'); + public function testWithPath() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withPath('/new-path'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('/path', $uri->getPath()); - $this->assertEquals('/new-path', $copy->getPath()); - } + $this->assertEquals('/path', $uri->getPath()); + $this->assertEquals('/new-path', $copy->getPath()); + } - public function testWithQuery() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withQuery('new-query'); + public function testWithQuery() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withQuery('new-query'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('query', $uri->getQuery()); - $this->assertEquals('new-query', $copy->getQuery()); - } + $this->assertEquals('query', $uri->getQuery()); + $this->assertEquals('new-query', $copy->getQuery()); + } - public function testWithFragment() - { - $uri = new Uri(self::TEST_URI); - $copy = $uri->withFragment('new-fragment'); + public function testWithFragment() + { + $uri = new Uri(self::TEST_URI); + $copy = $uri->withFragment('new-fragment'); - $this->assertInstanceOf(UriInterface::class, $copy); - $this->assertNotEquals($uri, $copy); + $this->assertInstanceOf(UriInterface::class, $copy); + $this->assertNotEquals($uri, $copy); - $this->assertEquals('fragment', $uri->getFragment()); - $this->assertEquals('new-fragment', $copy->getFragment()); - } + $this->assertEquals('fragment', $uri->getFragment()); + $this->assertEquals('new-fragment', $copy->getFragment()); + } - // Withers with empty data... + // Withers with empty data... - public function testWithEmptyScheme() - { - $uri = (new Uri(self::TEST_URI))->withScheme(''); + public function testWithEmptyScheme() + { + $uri = (new Uri(self::TEST_URI))->withScheme(''); - $this->assertEquals('', $uri->getScheme()); - } + $this->assertEquals('', $uri->getScheme()); + } - public function testWithEmptyUserInfo() - { - $uri = (new Uri(self::TEST_URI))->withUserInfo(''); + public function testWithEmptyUserInfo() + { + $uri = (new Uri(self::TEST_URI))->withUserInfo(''); - $this->assertEquals('', $uri->getUserInfo()); - } + $this->assertEquals('', $uri->getUserInfo()); + } - public function testWithEmptyHost() - { - $uri = (new Uri(self::TEST_URI))->withHost(''); + public function testWithEmptyHost() + { + $uri = (new Uri(self::TEST_URI))->withHost(''); - $this->assertEquals('', $uri->getHost()); - } + $this->assertEquals('', $uri->getHost()); + } - public function testWithEmptyPort() - { - $uri = (new Uri(self::TEST_URI))->withPort(null); + public function testWithEmptyPort() + { + $uri = (new Uri(self::TEST_URI))->withPort(null); - $this->assertEquals(null, $uri->getPort()); - } + $this->assertEquals(null, $uri->getPort()); + } - public function testWithEmptyPath() - { - $uri = (new Uri(self::TEST_URI))->withPath(''); + public function testWithEmptyPath() + { + $uri = (new Uri(self::TEST_URI))->withPath(''); - $this->assertEquals('', $uri->getPath()); - } + $this->assertEquals('', $uri->getPath()); + } - public function testWithEmptyQuery() - { - $uri = (new Uri(self::TEST_URI))->withQuery(''); + public function testWithEmptyQuery() + { + $uri = (new Uri(self::TEST_URI))->withQuery(''); - $this->assertEquals('', $uri->getQuery()); - } + $this->assertEquals('', $uri->getQuery()); + } - public function testWithEmptyFragment() - { - $uri = (new Uri(self::TEST_URI))->withFragment(''); + public function testWithEmptyFragment() + { + $uri = (new Uri(self::TEST_URI))->withFragment(''); - $this->assertEquals('', $uri->getFragment()); - } + $this->assertEquals('', $uri->getFragment()); + } - // Withers with invalid data... + // Withers with invalid data... - public function testWithInvalidScheme() - { - $this->expectException(InvalidUriComponentException::class); - $this->expectExceptionMessage('Invalid URI component "scheme"'); + public function testWithInvalidScheme() + { + $this->expectException(InvalidUriComponentException::class); + $this->expectExceptionMessage('Invalid URI component "scheme"'); - (new Uri(self::TEST_URI))->withScheme('scheme:'); - } + (new Uri(self::TEST_URI))->withScheme('scheme:'); + } - public function testWithInvalidUserInfo() - { - $uri = (new Uri(self::TEST_URI))->withUserInfo('user:pass', 'user:pass'); - - $this->assertEquals('user%3Apass:user%3Apass', $uri->getUserInfo(), '', 0.0, 10, false, true); - } - - public function testWithInvalidHost() - { - $uri = (new Uri(self::TEST_URI))->withHost('host:80'); - - $this->assertEquals('host%3A80', $uri->getHost(), '', 0.0, 10, false, true); - } - - public function testWithInvalidPortIsLessThanZero() - { - $this->expectException(InvalidUriComponentException::class); - $this->expectExceptionMessage('Invalid URI component "port"'); - - (new Uri(self::TEST_URI))->withPort(-1); - } - - public function testWithInvalidPortIsZero() - { - $this->expectException(InvalidUriComponentException::class); - $this->expectExceptionMessage('Invalid URI component "port"'); - - (new Uri(self::TEST_URI))->withPort(0); - } - - public function testWithInvalidPortIsTooLarge() - { - $this->expectException(InvalidUriComponentException::class); - $this->expectExceptionMessage('Invalid URI component "port"'); - - (new Uri(self::TEST_URI))->withPort((2 ** 16) + 1); - } - - public function testWithInvalidPath() - { - $uri = (new Uri(self::TEST_URI))->withPath('/path?query'); - - $this->assertEquals('/path%3Fquery', $uri->getPath(), '', 0.0, 10, false, true); - } - - public function testWithInvalidQuery() - { - $uri = (new Uri(self::TEST_URI))->withQuery('query#fragment'); - - $this->assertEquals('query%23fragment', $uri->getQuery(), '', 0.0, 10, false, true); - } - - public function testWithInvalidFragment() - { - $uri = (new Uri(self::TEST_URI))->withFragment('fragment#fragment'); - - $this->assertEquals('fragment%23fragment', $uri->getFragment(), '', 0.0, 10, false, true); - } - - // Withers with invalid data types... - - /** - * @dataProvider invalidDataTypeProviderForScheme - */ - public function testWithInvalidDataTypeForScheme($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "scheme" must be a string'); - - (new Uri)->withScheme($value); - } - - public function invalidDataTypeProviderForScheme() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForUser - */ - public function testWithInvalidDataTypeForUser($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "user" must be a string'); - - (new Uri)->withUserInfo($value); - } - - public function invalidDataTypeProviderForUser() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForPass - */ - public function testWithInvalidDataTypeForPass($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "pass" must be a string'); - - (new Uri)->withUserInfo('user', $value); - } - - public function invalidDataTypeProviderForPass() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForHost - */ - public function testWithInvalidDataTypeForHost($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "host" must be a string'); - - (new Uri)->withHost($value); - } - - public function invalidDataTypeProviderForHost() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForPort - */ - public function testWithInvalidDataTypeForPort($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "port" must be an integer'); - - (new Uri)->withPort($value); - } - - public function invalidDataTypeProviderForPort() - { - return [ - [true], - [false], - ['a'], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForPath - */ - public function testWithInvalidDataTypeForPath($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "path" must be a string'); - - (new Uri)->withPath($value); - } - - public function invalidDataTypeProviderForPath() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForQuery - */ - public function testWithInvalidDataTypeForQuery($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "query" must be a string'); - - (new Uri)->withQuery($value); - } - - public function invalidDataTypeProviderForQuery() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - /** - * @dataProvider invalidDataTypeProviderForFragment - */ - public function testWithInvalidDataTypeForFragment($value) - { - $this->expectException(\InvalidArgumentException::class); - $this->expectExceptionMessage('URI component "fragment" must be a string'); - - (new Uri)->withFragment($value); - } - - public function invalidDataTypeProviderForFragment() - { - return [ - [true], - [false], - [0], - [0.0], - [[]], - [new \stdClass], - [\STDOUT], - [null], - [function(){}], - ]; - } - - // Builders... - - public function testGetAuthority() - { - $uri = new Uri(self::TEST_URI); - - $this->assertEquals('user:pass@host:3000', $uri->getAuthority()); - - $this->assertEquals('', $uri->withHost('')->getAuthority()); - - $this->assertEquals('host:3000', $uri->withUserInfo('')->getAuthority()); - - $this->assertEquals('user@host:3000', $uri->withUserInfo('user')->getAuthority()); - - $this->assertEquals('user:pass@host', $uri->withPort(null)->getAuthority()); - } - - public function testToString() - { - $uri = new Uri(self::TEST_URI); - - $this->assertEquals(self::TEST_URI, (string) $uri); - } - - // Normalizes... - - public function testNormalizeScheme() - { - $uri = new Uri(self::TEST_URI); - - $uri = $uri->withScheme('UPPERCASED-SCHEME'); - - $this->assertEquals('uppercased-scheme', $uri->getScheme()); - } - - public function testNormalizeHost() - { - $uri = new Uri(self::TEST_URI); - - $uri = $uri->withHost('UPPERCASED-HOST'); - - $this->assertEquals('uppercased-host', $uri->getHost()); - } - - // Exceptions... - - public function testExceptions() - { - $this->assertInstanceOf(\InvalidArgumentException::class, new InvalidUriComponentException('')); - $this->assertInstanceOf(\InvalidArgumentException::class, new InvalidUriException('')); - } - - // Ignoring the standard ports - - public function testIgnoringStandardPorts() - { - $uri = new Uri('http://example.com:80/'); - $this->assertNull($uri->getPort()); - $this->assertEquals('example.com', $uri->getAuthority()); - $this->assertEquals('http://example.com/', (string) $uri); - - $uri = new Uri('https://example.com:443/'); - $this->assertNull($uri->getPort()); - $this->assertEquals('example.com', $uri->getAuthority()); - $this->assertEquals('https://example.com/', (string) $uri); - - $uri = new Uri('http://example.com:443/'); - $this->assertEquals(443, $uri->getPort()); - $this->assertEquals('example.com:443', $uri->getAuthority()); - $this->assertEquals('http://example.com:443/', (string) $uri); + public function testWithInvalidUserInfo() + { + $uri = (new Uri(self::TEST_URI))->withUserInfo('user:pass', 'user:pass'); - $uri = new Uri('https://example.com:80/'); - $this->assertEquals(80, $uri->getPort()); - $this->assertEquals('example.com:80', $uri->getAuthority()); - $this->assertEquals('https://example.com:80/', (string) $uri); - } + $this->assertEquals('user%3Apass:user%3Apass', $uri->getUserInfo(), '', 0.0, 10, false, true); + } - // Another schemes... + public function testWithInvalidHost() + { + $uri = (new Uri(self::TEST_URI))->withHost('host:80'); + + // %3A or %3a + $expected = \strtolower('host%3A80'); + + $this->assertEquals($expected, $uri->getHost(), '', 0.0, 10, false, true); + } + + public function testWithInvalidPortIsLessThanZero() + { + $this->expectException(InvalidUriComponentException::class); + $this->expectExceptionMessage('Invalid URI component "port"'); + + (new Uri(self::TEST_URI))->withPort(-1); + } + + public function testWithInvalidPortIsZero() + { + $this->expectException(InvalidUriComponentException::class); + $this->expectExceptionMessage('Invalid URI component "port"'); + + (new Uri(self::TEST_URI))->withPort(0); + } + + public function testWithInvalidPortIsTooLarge() + { + $this->expectException(InvalidUriComponentException::class); + $this->expectExceptionMessage('Invalid URI component "port"'); + + (new Uri(self::TEST_URI))->withPort((2 ** 16) + 1); + } + + public function testWithInvalidPath() + { + $uri = (new Uri(self::TEST_URI))->withPath('/path?query'); + + $this->assertEquals('/path%3Fquery', $uri->getPath(), '', 0.0, 10, false, true); + } + + public function testWithInvalidQuery() + { + $uri = (new Uri(self::TEST_URI))->withQuery('query#fragment'); + + $this->assertEquals('query%23fragment', $uri->getQuery(), '', 0.0, 10, false, true); + } + + public function testWithInvalidFragment() + { + $uri = (new Uri(self::TEST_URI))->withFragment('fragment#fragment'); + + $this->assertEquals('fragment%23fragment', $uri->getFragment(), '', 0.0, 10, false, true); + } + + // Withers with invalid data types... + + /** + * @dataProvider invalidDataTypeProviderForScheme + */ + public function testWithInvalidDataTypeForScheme($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "scheme" must be a string'); + + (new Uri)->withScheme($value); + } + + public function invalidDataTypeProviderForScheme() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForUser + */ + public function testWithInvalidDataTypeForUser($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "user" must be a string'); + + (new Uri)->withUserInfo($value); + } + + public function invalidDataTypeProviderForUser() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForPass + */ + public function testWithInvalidDataTypeForPass($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "pass" must be a string'); + + (new Uri)->withUserInfo('user', $value); + } + + public function invalidDataTypeProviderForPass() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForHost + */ + public function testWithInvalidDataTypeForHost($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "host" must be a string'); + + (new Uri)->withHost($value); + } + + public function invalidDataTypeProviderForHost() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForPort + */ + public function testWithInvalidDataTypeForPort($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "port" must be an integer'); + + (new Uri)->withPort($value); + } + + public function invalidDataTypeProviderForPort() + { + return [ + [true], + [false], + ['a'], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForPath + */ + public function testWithInvalidDataTypeForPath($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "path" must be a string'); + + (new Uri)->withPath($value); + } + + public function invalidDataTypeProviderForPath() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForQuery + */ + public function testWithInvalidDataTypeForQuery($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "query" must be a string'); + + (new Uri)->withQuery($value); + } + + public function invalidDataTypeProviderForQuery() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + /** + * @dataProvider invalidDataTypeProviderForFragment + */ + public function testWithInvalidDataTypeForFragment($value) + { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('URI component "fragment" must be a string'); + + (new Uri)->withFragment($value); + } + + public function invalidDataTypeProviderForFragment() + { + return [ + [true], + [false], + [0], + [0.0], + [[]], + [new \stdClass], + [\STDOUT], + [null], + [function () { + }], + ]; + } + + // Builders... + + public function testGetAuthority() + { + $uri = new Uri(self::TEST_URI); + + $this->assertEquals('user:pass@host:3000', $uri->getAuthority()); + + $this->assertEquals('', $uri->withHost('')->getAuthority()); + + $this->assertEquals('host:3000', $uri->withUserInfo('')->getAuthority()); + + $this->assertEquals('user@host:3000', $uri->withUserInfo('user')->getAuthority()); + + $this->assertEquals('user:pass@host', $uri->withPort(null)->getAuthority()); + } + + public function testToString() + { + $uri = new Uri(self::TEST_URI); + + $this->assertEquals(self::TEST_URI, (string) $uri); + } + + // Normalizes... + + public function testNormalizeScheme() + { + $uri = new Uri(self::TEST_URI); + + $uri = $uri->withScheme('UPPERCASED-SCHEME'); + + $this->assertEquals('uppercased-scheme', $uri->getScheme()); + } + + public function testNormalizeHost() + { + $uri = new Uri(self::TEST_URI); + + $uri = $uri->withHost('UPPERCASED-HOST'); + + $this->assertEquals('uppercased-host', $uri->getHost()); + } + + // Exceptions... + + public function testExceptions() + { + $this->assertInstanceOf(\InvalidArgumentException::class, new InvalidUriComponentException('')); + $this->assertInstanceOf(\InvalidArgumentException::class, new InvalidUriException('')); + } + + // Ignoring the standard ports + + public function testIgnoringStandardPorts() + { + $uri = new Uri('http://example.com:80/'); + $this->assertNull($uri->getPort()); + $this->assertEquals('example.com', $uri->getAuthority()); + $this->assertEquals('http://example.com/', (string) $uri); + + $uri = new Uri('https://example.com:443/'); + $this->assertNull($uri->getPort()); + $this->assertEquals('example.com', $uri->getAuthority()); + $this->assertEquals('https://example.com/', (string) $uri); + + $uri = new Uri('http://example.com:443/'); + $this->assertEquals(443, $uri->getPort()); + $this->assertEquals('example.com:443', $uri->getAuthority()); + $this->assertEquals('http://example.com:443/', (string) $uri); - public function testMailtoScheme() - { - $uri = new Uri('mailto:test@example.com'); + $uri = new Uri('https://example.com:80/'); + $this->assertEquals(80, $uri->getPort()); + $this->assertEquals('example.com:80', $uri->getAuthority()); + $this->assertEquals('https://example.com:80/', (string) $uri); + } - $this->assertEquals('mailto', $uri->getScheme()); - $this->assertEquals('test@example.com', $uri->getPath()); - } + // Another schemes... - public function testMapsScheme() - { - $uri = new Uri('maps:?q=112+E+Chapman+Ave+Orange,+CA+92866'); + public function testMailtoScheme() + { + $uri = new Uri('mailto:test@example.com'); - $this->assertEquals('maps', $uri->getScheme()); - $this->assertEquals('q=112+E+Chapman+Ave+Orange,+CA+92866', $uri->getQuery()); - } + $this->assertEquals('mailto', $uri->getScheme()); + $this->assertEquals('test@example.com', $uri->getPath()); + } - public function testTelScheme() - { - $uri = new Uri('tel:+1-816-555-1212'); + public function testMapsScheme() + { + $uri = new Uri('maps:?q=112+E+Chapman+Ave+Orange,+CA+92866'); - $this->assertEquals('tel', $uri->getScheme()); - $this->assertEquals('+1-816-555-1212', $uri->getPath()); - } + $this->assertEquals('maps', $uri->getScheme()); + $this->assertEquals('q=112+E+Chapman+Ave+Orange,+CA+92866', $uri->getQuery()); + } - public function testUrnScheme() - { - $uri = new Uri('urn:oasis:names:specification:docbook:dtd:xml:4.1.2'); + public function testTelScheme() + { + $uri = new Uri('tel:+1-816-555-1212'); - $this->assertEquals('urn', $uri->getScheme()); - $this->assertEquals('oasis:names:specification:docbook:dtd:xml:4.1.2', $uri->getPath()); - } + $this->assertEquals('tel', $uri->getScheme()); + $this->assertEquals('+1-816-555-1212', $uri->getPath()); + } + + public function testUrnScheme() + { + $uri = new Uri('urn:oasis:names:specification:docbook:dtd:xml:4.1.2'); + + $this->assertEquals('urn', $uri->getScheme()); + $this->assertEquals('oasis:names:specification:docbook:dtd:xml:4.1.2', $uri->getPath()); + } } From 7253144dd1036c81646cdea4f135fca4cde97d71 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:26:24 +0500 Subject: [PATCH 6/8] new ignored files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index c331141..41cf726 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +.php_cs.cache +.phpunit.result.cache composer.lock coverage.xml +phpcs.xml +phpunit.xml vendor/ From 03ed0795220fc0ca70f58182a789fe470e5e9c40 Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:26:37 +0500 Subject: [PATCH 7/8] php8 support --- composer.json | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 9d5a7c1..fc30fd7 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,20 @@ { "name": "sunrise/uri", - "description": "Simple URI wrapper for PHP 7.1+ based on RFC-3986, PSR-7 & PSR-17", - "keywords": ["fenric", "sunrise", "uri", "parser", "rfc-3986", "psr-7", "psr-17"], "homepage": "https://github.com/sunrise-php/uri", + "description": "Simple URI wrapper for PHP 7.1+ based on RFC-3986, PSR-7 & PSR-17", "license": "MIT", + "keywords": [ + "fenric", + "sunrise", + "http", + "uri", + "parser", + "rfc-3986", + "psr-7", + "psr-17", + "php7", + "php8" + ], "authors": [ { "name": "Anatoly Fenric", @@ -17,12 +28,13 @@ } ], "require": { - "php": "^7.1", + "php": "^7.1|^8.0", "psr/http-factory": "^1.0", "psr/http-message": "^1.0" }, "require-dev": { - "phpunit/phpunit": "7.5.6" + "phpunit/phpunit": "7.5.20|9.5.0", + "sunrise/coding-standard": "1.0.0" }, "provide": { "psr/http-message-implementation": "1.0" @@ -34,7 +46,8 @@ }, "scripts": { "test": [ - "phpunit --colors=always --coverage-text" + "phpunit --colors=always --coverage-text", + "phpcs" ] } } From 401c5fab4413d19cefe8a402cdff6fbce62700ce Mon Sep 17 00:00:00 2001 From: Anatoly Nekhay Date: Fri, 25 Dec 2020 09:26:53 +0500 Subject: [PATCH 8/8] new configuration --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7b697c1..b0e5e8d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 + - php: nightly fast_finish: true before_install: @@ -13,4 +15,4 @@ before_install: install: - travis_retry composer install --no-interaction --prefer-source --no-suggest -script: vendor/bin/phpunit --colors=always --coverage-text +script: php vendor/bin/phpunit --colors=always --coverage-text