/**
  * Method to test getUri().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Request\AbstractRequest::getUri
  * @covers \Windwalker\Http\Request\AbstractRequest::withUri
  */
 public function testWithAndGetUri()
 {
     $this->assertInstanceOf('Windwalker\\Uri\\PsrUri', $this->instance->getUri());
     $this->assertEquals('', (string) $this->instance->getUri());
     $request = $this->instance->withUri(new PsrUri('http://example.com/flower/sakura?foo=bar#baz'), true);
     $this->assertNotSame($request, $this->instance);
     $this->assertEquals('http://example.com/flower/sakura?foo=bar#baz', (string) $request->getUri());
     $this->assertEquals(array(), $request->getHeader('host'));
     $request = $this->instance->withUri(new PsrUri('http://windwalker.io/flower/sakura?foo=bar#baz'));
     $this->assertEquals('http://windwalker.io/flower/sakura?foo=bar#baz', (string) $request->getUri());
     $this->assertEquals(array('windwalker.io'), $request->getHeader('host'));
 }
Exemplo n.º 2
0
 /**
  * Checks if a header exists by the given case-insensitive name.
  *
  * @param string $name Case-insensitive header field name.
  *
  * @return bool Returns true if any header names match the given header
  *     name using a case-insensitive string comparison. Returns false if
  *     no matching header name is found in the message.
  */
 public function hasHeader($name)
 {
     if (strtolower($name) === 'host' && ($this->uri && $this->uri->getHost())) {
         $this->headerNames['host'] = $name;
         $this->headers[$name] = array($this->getHostFromUri());
     }
     return parent::hasHeader($name);
 }
Exemplo n.º 3
0
 /**
  * Class init
  *
  * @param   array                           $serverParams  Server parameters, typically from $_SERVER
  * @param   UploadedFileInterface[]         $uploadedFiles Upload file information, a tree of UploadedFiles
  * @param   string                          $uri           URI for the request, if any.
  * @param   string                          $method        HTTP method for the request, if any.
  * @param   string|resource|StreamInterface $body          Message body, if any.
  * @param   array                           $headers       Headers for the message, if any.
  * @param   array                           $cookies       Cookie values, typically is $_COOKIE.
  * @param   array                           $queryParams   Http query, typically is $_GET.
  * @param   string                          $parsedBody    Parsed body, typically is $_POST.
  * @param   string                          $protocol      The protocol version, default is 1.1.
  */
 public function __construct(array $serverParams = array(), array $uploadedFiles = array(), $uri = null, $method = null, $body = 'php://input', array $headers = array(), array $cookies = array(), array $queryParams = array(), $parsedBody = null, $protocol = '1.1')
 {
     if (!ServerHelper::validateUploadedFiles($uploadedFiles)) {
         throw new \InvalidArgumentException('Invalid uploaded files, every file should be an UploadedInterface');
     }
     if ($body == 'php://input') {
         $body = new PhpInputStream();
     }
     $this->serverParams = $serverParams;
     $this->uploadedFiles = $uploadedFiles;
     $this->cookieParams = $cookies;
     $this->queryParams = $queryParams;
     $this->parsedBody = $parsedBody;
     $this->protocol = $protocol;
     parent::__construct($uri, $method, $body, $headers);
 }