src/Phpcsp/Security/ContentSecurityPolicyHeaderBuilder.php
public static function extractOrigin($uri)
    {
        $parts = parse_url($uri);

        // parse_url returns false when the uri is seriously malformed
        if (!is_array($parts)) {
            return false;
        }

        if (isset($parts['scheme']) && isset($parts['host'])) {
            if (isset($parts['port'])) {
                return sprintf('%s://%s:%s', $parts['scheme'], $parts['host'], $parts['port']);
            } else {
                return sprintf('%s://%s', $parts['scheme'], $parts['host']);
            }
        }

        return false;
    }
public static function extractOrigin($uri)
    {
        $parts = parse_url($uri);

        // parse_url returns false when the uri is seriously malformed
        if (!is_array($parts)) {
            return false;
        }

        if (isset($parts['scheme']) && isset($parts['host'])) {
            if (isset($parts['port'])) {
                return sprintf('%s://%s:%s', $parts['scheme'], $parts['host'], $parts['port']);
            } else {
                return sprintf('%s://%s', $parts['scheme'], $parts['host']);
            }
        }

        return false;
    }
Extracts the (serialized) origin from a uri or false on failure.

@param string $uri
@return false|string