scheme(); if ($scheme === null || $scheme === '') { throw new InvalidArgumentException("URL has no scheme: {$url}"); } if (! in_array($scheme, ['http', 'https'], true)) { throw new InvalidArgumentException("Invalid URL scheme: {$scheme}"); } if ($uri->user() !== null) { throw new InvalidArgumentException("URLs with embedded credentials not allowed: {$url}"); } $host = $uri->host(); if ($host === null || $host === '') { throw new InvalidArgumentException("URL has no host: {$url}"); } $bareHost = preg_replace('/%.*$/', '', trim($host, '[]')); if (filter_var($bareHost, FILTER_VALIDATE_IP) !== false) { throw new InvalidArgumentException("IP literal hosts not allowed: {$host}"); } return mb_strtolower($host); } }