コード例 #1
0
ファイル: UriTest.php プロジェクト: cerad/http
 public function testParams()
 {
     $params = ['host' => 'localhost', 'path' => '/referees'];
     $uri = new Uri($params);
     $this->assertEquals('localhost', $uri->getHost());
     $this->assertEquals('/referees', $uri->getPath());
 }
コード例 #2
0
ファイル: Request.php プロジェクト: cerad/http
 protected function createFromRequestLine($requestLine, $headers = [], $contents = null)
 {
     // GET url PROTOCOL
     $parts = explode(' ', $requestLine);
     switch (count($parts)) {
         case 1:
             $url = $parts[0];
             // No method, probably bad
             break;
         case 2:
             $this->method = $this->checkMethod($parts[0]);
             $url = $parts[1];
             break;
         default:
             $this->method = $this->checkMethod($parts[0]);
             $url = $parts[1];
             $this->protocolVersion = $this->checkProtocolVersion($parts[2]);
     }
     $this->uri = $uri = new Uri($url);
     if (!isset($headers['Host'])) {
         $headers['Host'] = $uri->getHost();
     }
     if (!isset($headers['Content-Type'])) {
         $headers['Content-Type'] = 'text/plain';
     }
     $this->setHeaders($headers);
     // This should always be the case
     $this->routePath = $uri->getPath();
     // baseHref is always just / for now
     $this->baseHrefAbs = $uri->getScheme() . '://' . $uri->getAuthority() . $this->baseHref;
     // The target is what was passed in
     $this->requestTarget = $url;
     // Parse any query params
     parse_str($uri->getQuery(), $this->queryParams);
     // Create and parse the body
     $this->body = new Body($contents);
     $this->parsedBody = $this->parseBody();
 }