public function __construct(Options $options, OutputInterface $ouput) { $timeout = $options->getTimeout(); $client = new ClientGuzzle(['timeout' => $timeout]); $url = $options->getUrl(); $response = $client->get($url); if ($response->getStatusCode() != 200) { throw new RuntimeException(sprintf('Cannot access this url: "%s"', $url)); } $uri = new Uri($url); $baseUri = $uri->getScheme() . '://' . $uri->getHost(); if (!empty($uri->getPort())) { $baseUri .= ':' . $uri->getPort(); } $options->setBaseUri($baseUri); $this->options = $options; $this->output = $ouput; }
public function testAllowsFalseyUrlParts() { $url = new Uri('http://a:1/0?0#0'); $this->assertSame('a', $url->getHost()); $this->assertEquals(1, $url->getPort()); $this->assertSame('/0', $url->getPath()); $this->assertEquals('0', (string) $url->getQuery()); $this->assertSame('0', $url->getFragment()); $this->assertEquals('http://a:1/0?0#0', (string) $url); $url = new Uri(''); $this->assertSame('', (string) $url); $url = new Uri('0'); $this->assertSame('/0', (string) $url); }
protected function assertUriEquals($expectedUri, $actualUri) { if (is_string($expectedUri)) { $expectedUri = new Psr7\Uri($expectedUri); } if (is_string($actualUri)) { $actualUri = new Psr7\Uri($actualUri); } $this->assertEquals($expectedUri->getScheme(), $actualUri->getScheme()); $this->assertEquals($expectedUri->getPort(), $actualUri->getPort()); $this->assertEquals($expectedUri->getHost(), $actualUri->getHost()); $this->assertEquals($expectedUri->getPath(), $actualUri->getPath()); $expectedQueryParts = Psr7\parse_query($expectedUri->getQuery()); $actualQueryParts = Psr7\parse_query($actualUri->getQuery()); $this->assertEquals($expectedQueryParts, $actualQueryParts); }
private function extractHeaders(BrowserKitRequest $request) { $headers = []; $server = $request->getServer(); $uri = new Uri($request->getUri()); $server['HTTP_HOST'] = $uri->getHost(); $port = $uri->getPort(); if ($port !== null && $port !== 443 && $port != 80) { $server['HTTP_HOST'] .= ':' . $port; } $contentHeaders = array('Content-Length' => true, 'Content-Md5' => true, 'Content-Type' => true); foreach ($server as $header => $val) { $header = implode('-', array_map('ucfirst', explode('-', strtolower(str_replace('_', '-', $header))))); if (strpos($header, 'Http-') === 0) { $headers[substr($header, 5)] = $val; } elseif (isset($contentHeaders[$header])) { $headers[$header] = $val; } } return $headers; }
public function testDefaultReturnValuesOfGetters() { $uri = new Uri(); $this->assertSame('', $uri->getScheme()); $this->assertSame('', $uri->getAuthority()); $this->assertSame('', $uri->getUserInfo()); $this->assertSame('', $uri->getHost()); $this->assertNull($uri->getPort()); $this->assertSame('', $uri->getPath()); $this->assertSame('', $uri->getQuery()); $this->assertSame('', $uri->getFragment()); }