getHost() public method

public getHost ( )
 /**
  * Initialize the stream client and resources
  *
  * @param string $path
  */
 protected function initialize($path)
 {
     $uri = new Uri($path);
     if (!ctype_digit($uri->getHost())) {
         throw new \InvalidArgumentException(sprintf('path "%s" must be of type integer', $path));
     }
     $this->length = (int) $uri->getHost();
 }
示例#2
0
 protected function request($method, $url, $params = [], $headers = [])
 {
     $jar = $this->cache->has($this->tabName) ? $this->cache->get($this->tabName) : new CookieJar();
     $url = new Uri($url);
     $headers = array_merge(['Content-Type' => 'application/x-www-form-urlencoded; charset=UTF-8', 'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36', 'Host' => $url->getHost(), 'Origin' => $url->getScheme() . "://" . $url->getHost() . "/"], $headers);
     $stack = HandlerStack::create();
     $stack->push(Middleware::mapRequest(function (RequestInterface $request) {
         $URI = $request->getUri();
         $this->baseUri = $URI->__toString();
         return $request->withUri($URI);
     }));
     $client = new Client(["cookies" => $jar, 'handler' => $stack, 'verify' => __DIR__ . '/../cacert.pem']);
     $request = new GuzzleHttpRequest($method, $url, $headers, http_build_query($params));
     $this->response = $client->send($request, ['timeout' => 120]);
     $this->cache->put($this->tabName, $jar, 24 * 60);
 }
 public function register(Container $pimple)
 {
     // File extensions used to determine whether a URI points to an asset
     // or an HTML file.
     $pimple['html_extensions'] = static::$html_extensions;
     $pimple['asset_extensions'] = static::$asset_extensions;
     // Matches any URI we think points to an HTML page.
     $pimple['matcher.html'] = function () use($pimple) {
         return Matcher::all()->pathExtensionIs($pimple['html_extensions']);
     };
     // Matches any URI we think points to an asset file.
     $pimple['matcher.asset'] = function () use($pimple) {
         return Matcher::all()->pathExtensionIs($pimple['asset_extensions']);
     };
     // Matches any URI that is considered "in scope."
     $pimple['matcher.internal'] = function () use($pimple) {
         $uri = new Uri($pimple['base_url']);
         return Matcher::all()->schemeIs($uri->getScheme())->hostIs($uri->getHost())->pathMatches('~^' . preg_quote($uri->getPath(), '~') . '~');
     };
     // Matches any URI that is both internal and HTML.
     $pimple['matcher.internal_html'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.html']);
     };
     // Matches any URI that is both internal and an asset.
     $pimple['matcher.internal_asset'] = function () use($pimple) {
         return Matcher::all()->add($pimple['matcher.internal'])->add($pimple['matcher.asset']);
     };
 }
示例#4
0
 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);
 }
示例#6
0
 /**
  * Generate a base string for a HMAC-SHA1 signature
  * based on the given a url, method, and any parameters.
  *
  * @param Url    $url
  * @param string $method
  * @param array  $parameters
  *
  * @return string
  */
 protected function baseString(Uri $url, $method = 'POST', array $parameters = array())
 {
     $baseString = rawurlencode($method) . '&';
     $schemeHostPath = Uri::fromParts(array('scheme' => $url->getScheme(), 'host' => $url->getHost(), 'path' => $url->getPath()));
     $baseString .= rawurlencode($schemeHostPath) . '&';
     $data = array();
     parse_str($url->getQuery(), $query);
     $data = array_merge($query, $parameters);
     // normalize data key/values
     array_walk_recursive($data, function (&$key, &$value) {
         $key = rawurlencode(rawurldecode($key));
         $value = rawurlencode(rawurldecode($value));
     });
     ksort($data);
     $baseString .= $this->queryStringFromData($data);
     return $baseString;
 }
示例#7
0
 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;
 }
示例#8
0
 /**
  * @param null|string $method HTTP method for the request.
  * @param null|string $uri URI for the request.
  * @param array  $headers Headers for the message.
  * @param string|resource|StreamInterface $body Message body.
  * @param string $protocolVersion HTTP protocol version.
  *
  * @throws InvalidArgumentException for an invalid URI
  */
 public function __construct($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
 {
     if (is_string($uri)) {
         $uri = new Uri($uri);
     } elseif (!$uri instanceof UriInterface) {
         throw new \InvalidArgumentException('URI must be a string or Psr\\Http\\Message\\UriInterface');
     }
     $this->method = strtoupper($method);
     $this->uri = $uri;
     $this->setHeaders($headers);
     $this->protocol = $protocolVersion;
     $host = $uri->getHost();
     if ($host && !$this->hasHeader('Host')) {
         $this->updateHostFromUri($host);
     }
     if ($body) {
         $this->stream = stream_for($body);
     }
 }
示例#9
0
 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;
 }
示例#10
0
 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());
 }