Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / zendframework / zend-diactoros / src / Uri.php
index 8900e3746e165fe34811a19a2278bb5bb479b38e..5dcfb0e235253f4e17f6f78422a24ae4bf77618b 100644 (file)
@@ -10,6 +10,26 @@ namespace Zend\Diactoros;
 use InvalidArgumentException;
 use Psr\Http\Message\UriInterface;
 
+use function array_key_exists;
+use function array_keys;
+use function count;
+use function explode;
+use function get_class;
+use function gettype;
+use function implode;
+use function is_numeric;
+use function is_object;
+use function is_string;
+use function ltrim;
+use function parse_url;
+use function preg_replace;
+use function preg_replace_callback;
+use function rawurlencode;
+use function sprintf;
+use function strpos;
+use function strtolower;
+use function substr;
+
 /**
  * Implementation of Psr\Http\UriInterface.
  *
@@ -91,16 +111,18 @@ class Uri implements UriInterface
      */
     public function __construct($uri = '')
     {
+        if ('' === $uri) {
+            return;
+        }
+
         if (! is_string($uri)) {
             throw new InvalidArgumentException(sprintf(
                 'URI passed to constructor must be a string; received "%s"',
-                (is_object($uri) ? get_class($uri) : gettype($uri))
+                is_object($uri) ? get_class($uri) : gettype($uri)
             ));
         }
 
-        if (! empty($uri)) {
-            $this->parseUri($uri);
-        }
+        $this->parseUri($uri);
     }
 
     /**
@@ -147,12 +169,12 @@ class Uri implements UriInterface
      */
     public function getAuthority()
     {
-        if (empty($this->host)) {
+        if ('' === $this->host) {
             return '';
         }
 
         $authority = $this->host;
-        if (! empty($this->userInfo)) {
+        if ('' !== $this->userInfo) {
             $authority = $this->userInfo . '@' . $authority;
         }
 
@@ -226,7 +248,7 @@ class Uri implements UriInterface
             throw new InvalidArgumentException(sprintf(
                 '%s expects a string argument; received %s',
                 __METHOD__,
-                (is_object($scheme) ? get_class($scheme) : gettype($scheme))
+                is_object($scheme) ? get_class($scheme) : gettype($scheme)
             ));
         }
 
@@ -257,19 +279,19 @@ class Uri implements UriInterface
             throw new InvalidArgumentException(sprintf(
                 '%s expects a string user argument; received %s',
                 __METHOD__,
-                (is_object($user) ? get_class($user) : gettype($user))
+                is_object($user) ? get_class($user) : gettype($user)
             ));
         }
         if (null !== $password && ! is_string($password)) {
             throw new InvalidArgumentException(sprintf(
-                '%s expects a string password argument; received %s',
+                '%s expects a string or null password argument; received %s',
                 __METHOD__,
-                (is_object($password) ? get_class($password) : gettype($password))
+                is_object($password) ? get_class($password) : gettype($password)
             ));
         }
 
         $info = $this->filterUserInfoPart($user);
-        if ($password) {
+        if (null !== $password) {
             $info .= ':' . $this->filterUserInfoPart($password);
         }
 
@@ -293,7 +315,7 @@ class Uri implements UriInterface
             throw new InvalidArgumentException(sprintf(
                 '%s expects a string argument; received %s',
                 __METHOD__,
-                (is_object($host) ? get_class($host) : gettype($host))
+                is_object($host) ? get_class($host) : gettype($host)
             ));
         }
 
@@ -313,14 +335,14 @@ class Uri implements UriInterface
      */
     public function withPort($port)
     {
-        if (! is_numeric($port) && $port !== null) {
-            throw new InvalidArgumentException(sprintf(
-                'Invalid port "%s" specified; must be an integer, an integer string, or null',
-                (is_object($port) ? get_class($port) : gettype($port))
-            ));
-        }
-
         if ($port !== null) {
+            if (! is_numeric($port) || is_float($port)) {
+                throw new InvalidArgumentException(sprintf(
+                    'Invalid port "%s" specified; must be an integer, an integer string, or null',
+                    is_object($port) ? get_class($port) : gettype($port)
+                ));
+            }
+
             $port = (int) $port;
         }
 
@@ -417,7 +439,7 @@ class Uri implements UriInterface
             throw new InvalidArgumentException(sprintf(
                 '%s expects a string argument; received %s',
                 __METHOD__,
-                (is_object($fragment) ? get_class($fragment) : gettype($fragment))
+                is_object($fragment) ? get_class($fragment) : gettype($fragment)
             ));
         }
 
@@ -476,27 +498,26 @@ class Uri implements UriInterface
     {
         $uri = '';
 
-        if (! empty($scheme)) {
+        if ('' !== $scheme) {
             $uri .= sprintf('%s:', $scheme);
         }
 
-        if (! empty($authority)) {
+        if ('' !== $authority) {
             $uri .= '//' . $authority;
         }
 
-        if ($path) {
-            if (empty($path) || '/' !== substr($path, 0, 1)) {
-                $path = '/' . $path;
-            }
-
-            $uri .= $path;
+        if ('' !== $path && '/' !== substr($path, 0, 1)) {
+            $path = '/' . $path;
         }
 
-        if ($query) {
+        $uri .= $path;
+
+
+        if ('' !== $query) {
             $uri .= sprintf('?%s', $query);
         }
 
-        if ($fragment) {
+        if ('' !== $fragment) {
             $uri .= sprintf('#%s', $fragment);
         }
 
@@ -513,14 +534,11 @@ class Uri implements UriInterface
      */
     private function isNonStandardPort($scheme, $host, $port)
     {
-        if (! $scheme) {
-            if ($host && ! $port) {
-                return false;
-            }
-            return true;
+        if ('' === $scheme) {
+            return '' === $host || null !== $port;
         }
 
-        if (! $host || ! $port) {
+        if ('' === $host || null === $port) {
             return false;
         }
 
@@ -539,11 +557,11 @@ class Uri implements UriInterface
         $scheme = strtolower($scheme);
         $scheme = preg_replace('#:(//)?$#', '', $scheme);
 
-        if (empty($scheme)) {
+        if ('' === $scheme) {
             return '';
         }
 
-        if (! array_key_exists($scheme, $this->allowedSchemes)) {
+        if (! isset($this->allowedSchemes[$scheme])) {
             throw new InvalidArgumentException(sprintf(
                 'Unsupported scheme "%s"; must be any empty string or in the set (%s)',
                 $scheme,
@@ -585,7 +603,7 @@ class Uri implements UriInterface
             $path
         );
 
-        if (empty($path)) {
+        if ('' === $path) {
             // No path
             return $path;
         }
@@ -609,7 +627,7 @@ class Uri implements UriInterface
      */
     private function filterQuery($query)
     {
-        if (! empty($query) && strpos($query, '?') === 0) {
+        if ('' !== $query && strpos($query, '?') === 0) {
             $query = substr($query, 1);
         }
 
@@ -639,7 +657,7 @@ class Uri implements UriInterface
     private function splitQueryValue($value)
     {
         $data = explode('=', $value, 2);
-        if (1 === count($data)) {
+        if (! isset($data[1])) {
             $data[] = null;
         }
         return $data;
@@ -653,7 +671,7 @@ class Uri implements UriInterface
      */
     private function filterFragment($fragment)
     {
-        if (! empty($fragment) && strpos($fragment, '#') === 0) {
+        if ('' !== $fragment && strpos($fragment, '#') === 0) {
             $fragment = '%23' . substr($fragment, 1);
         }