Exemplo n.º 1
0
 public function testNewInstanceWhenNewCookieParams()
 {
     $cookieParams = ['testK' => 'testV'];
     $serverRequest = $this->serverRequest->withCookieParams($cookieParams);
     $this->assertNotSame($this->serverRequest, $serverRequest);
     $this->assertEquals($cookieParams, $serverRequest->getCookieParams());
 }
Exemplo n.º 2
0
 public function testCookieParams()
 {
     $request1 = new ServerRequest('GET', '/');
     $params = ['name' => 'value'];
     $request2 = $request1->withCookieParams($params);
     $this->assertNotSame($request2, $request1);
     $this->assertEmpty($request1->getCookieParams());
     $this->assertSame($params, $request2->getCookieParams());
 }
Exemplo n.º 3
0
 /**
  * Return a ServerRequest populated with superglobals:
  * $_GET
  * $_POST
  * $_COOKIE
  * $_FILES
  * $_SERVER
  *
  * @return ServerRequestInterface
  */
 public static function fromGlobals()
 {
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
     $headers = function_exists('getallheaders') ? getallheaders() : [];
     $uri = self::getUriFromGlobals();
     $body = new LazyOpenStream('php://input', 'r+');
     $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? str_replace('HTTP/', '', $_SERVER['SERVER_PROTOCOL']) : '1.1';
     $serverRequest = new ServerRequest($method, $uri, $headers, $body, $protocol, $_SERVER);
     return $serverRequest->withCookieParams($_COOKIE)->withQueryParams($_GET)->withParsedBody($_POST)->withUploadedFiles(self::normalizeFiles($_FILES));
 }