/** * testWithScheme * * @return void */ public function testWithScheme() { $uri = new PsrUri('https://*****:*****@local.example.com:3001/foo?bar=baz#quz'); $new = $uri->withScheme('http'); $this->assertNotSame($uri, $new); $this->assertEquals('http', $new->getScheme()); $this->assertEquals('http://*****:*****@local.example.com:3001/foo?bar=baz#quz', (string) $new); $new = $uri->withScheme('https://'); $this->assertEquals('https', $new->getScheme()); }
/** * Marshal the URI from the $_SERVER array and headers * * @param array $server The $_SERVER superglobal. * @param array $headers The headers variable from server. * * @return PsrUri Prepared Uri object. */ public static function prepareUri(array $server, array $headers) { $uri = new PsrUri(''); // URI scheme $scheme = 'http'; $https = ServerHelper::getValue($server, 'HTTPS'); // Is https or not if ($https && $https !== 'off' || HeaderHelper::getValue($headers, 'x-forwarded-proto', false) === 'https') { $scheme = 'https'; } // URI host $host = ''; $port = null; static::getHostAndPortFromHeaders($host, $port, $server, $headers); // URI path $path = static::getRequestUri($server); $path = static::stripQueryString($path); // URI query $query = ''; if (isset($server['QUERY_STRING'])) { $query = ltrim($server['QUERY_STRING'], '?'); } // URI fragment $fragment = ''; if (strpos($path, '#') !== false) { list($path, $fragment) = explode('#', $path, 2); } return $uri->withScheme($scheme)->withHost($host)->withPort($port)->withPath($path)->withFragment($fragment)->withQuery($query); }