PluginProbe
Metricool – Social media and site statistics / 2.1.1
Metricool – Social media and site statistics v2.1.1
2.1.1 2.1.0 2.0.2 2.0.1 2.0.0 1.27 trunk
metricool / vendor / _scoped / guzzlehttp / psr7 / src / UriComparator.php

UriComparator.php in Metricool – Social media and site statistics 2.1.1, at vendor/_scoped/guzzlehttp/psr7/src/UriComparator.php

50 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace Metricool\Vendor\GuzzleHttp\Psr7;
5
6 use Metricool\Vendor\Psr\Http\Message\UriInterface;
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 public static function isCrossOrigin(UriInterface $original, UriInterface $modified): bool
19 {
20 if (!Utils::caselessEquals($original->getHost(), $modified->getHost())) {
21 return \true;
22 }
23 if ($original->getScheme() !== $modified->getScheme()) {
24 return \true;
25 }
26 if (self::computePort($original) !== self::computePort($modified)) {
27 return \true;
28 }
29 return \false;
30 }
31 private static function computePort(UriInterface $uri): ?int
32 {
33 $port = $uri->getPort();
34 if (null !== $port) {
35 return $port;
36 }
37 if ('http' === $uri->getScheme()) {
38 return 80;
39 }
40 if ('https' === $uri->getScheme()) {
41 return 443;
42 }
43 return null;
44 }
45 private function __construct()
46 {
47 // cannot be instantiated
48 }
49 }
50