CoreFiles by mySites.guru
UriComparator.php60 lines, 1,273 bytes, from Joomla_6.2.0-alpha2-Alpha-Full_Package.zip
Raw History Compare with 6.2.0-alpha1
md5
ff94ae378e68ac69caca927daf28e263
sha1
d1c8f57d4436f19c3823ae3dcdb3c6e81cfd114e
sha256
31c4cf53b1a3ac28a19cf3b28a791697d14da0c23cb6efb313f4b0f020922da5
<?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;
        }

        if ('http' === $uri->getScheme()) {
            return 80;
        }

        if ('https' === $uri->getScheme()) {
            return 443;
        }

        return null;
    }

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

The same content is in 30 releases, Joomla 5.4.7-rc1 to 6.3.0-alpha1. See them all, or every version of this file.