CoreFiles by mySites.guru
UriComparator.php52 lines, 1,150 bytes, from Joomla_5.3.4-Stable-Full_Package.zip
Raw History Compare with 5.3.3
md5
e2b48e5aa2d22614a015290b40ee7bf7
sha1
a9d3a75a2138fff6a665f057c53a70b9ba7861c5
sha256
76fd693bd93822d5e5a11ba5a56328dc0aeed1639c4b0969ab7f8f9204f4989e
<?php

declare(strict_types=1);

namespace GuzzleHttp\Psr7;

use Psr\Http\Message\UriInterface;

/**
 * Provides methods to determine if a modified URL should be considered cross-origin.
 *
 * @author Graham Campbell
 */
final class UriComparator
{
    /**
     * Determines if a modified URL should be considered cross-origin with
     * respect to an original URL.
     */
    public static function isCrossOrigin(UriInterface $original, UriInterface $modified): bool
    {
        if (\strcasecmp($original->getHost(), $modified->getHost()) !== 0) {
            return true;
        }

        if ($original->getScheme() !== $modified->getScheme()) {
            return true;
        }

        if (self::computePort($original) !== self::computePort($modified)) {
            return true;
        }

        return false;
    }

    private static function computePort(UriInterface $uri): int
    {
        $port = $uri->getPort();

        if (null !== $port) {
            return $port;
        }

        return 'https' === $uri->getScheme() ? 443 : 80;
    }

    private function __construct()
    {
        // cannot be instantiated
    }
}

The same content is in 106 releases, Joomla 5.1.0-beta1 to 6.2.0-alpha1. See them all, or every version of this file.