Example #1
0
 /**
  * Method to test getUri().
  *
  * @return void
  *
  * @covers Asika\Http\AbstractRequest::getUri
  * @covers Asika\Http\AbstractRequest::withUri
  */
 public function testWithAndGetUri()
 {
     $this->assertInstanceOf('Asika\\Http\\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'));
 }
Example #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);
 }
Example #3
0
 /**
  * Class init
  *
  * @param   array                            $serverParams   Server parameters, typically from $_SERVER
  * @param   array                            $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.
  *
  * @throws \InvalidArgumentException
  */
 public function __construct(array $serverParams = array(), array $uploadedFiles = array(), $uri = null, $method = null, $body = 'php://input', array $headers = array())
 {
     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;
     parent::__construct($uri, $method, $body, $headers);
 }