| 1 |
<?php |
| 2 |
|
| 3 |
namespace GuzzleHttp\Psr7; |
| 4 |
|
| 5 |
use Psr\Http\Message\UriInterface; |
| 6 |
|
| 7 |
/** |
| 8 |
* Provides methods to determine if a modified URL should be considered cross-origin. |
| 9 |
* |
| 10 |
* @author Graham Campbell |
| 11 |
*/ |
| 12 |
final class UriComparator |
| 13 |
{ |
| 14 |
/** |
| 15 |
* Determines if a modified URL should be considered cross-origin with |
| 16 |
* respect to an original URL. |
| 17 |
* |
| 18 |
* @return bool |
| 19 |
*/ |
| 20 |
public static function isCrossOrigin(UriInterface $original, UriInterface $modified) |
| 21 |
{ |
| 22 |
if (\strcasecmp($original->getHost(), $modified->getHost()) !== 0) { |
| 23 |
return true; |
| 24 |
} |
| 25 |
|
| 26 |
if ($original->getScheme() !== $modified->getScheme()) { |
| 27 |
return true; |
| 28 |
} |
| 29 |
|
| 30 |
if (self::computePort($original) !== self::computePort($modified)) { |
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
return false; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* @return int |
| 39 |
*/ |
| 40 |
private static function computePort(UriInterface $uri) |
| 41 |
{ |
| 42 |
$port = $uri->getPort(); |
| 43 |
|
| 44 |
if (null !== $port) { |
| 45 |
return $port; |
| 46 |
} |
| 47 |
|
| 48 |
return 'https' === $uri->getScheme() ? 443 : 80; |
| 49 |
} |
| 50 |
|
| 51 |
private function __construct() |
| 52 |
{ |
| 53 |
// cannot be instantiated |
| 54 |
} |
| 55 |
} |
| 56 |
|