/**
  * {@inheritdoc}
  */
 public function createServerRequestFromGlobals()
 {
     $server = $_SERVER;
     $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($uri, $method, $headers, $body, $protocol, $server);
     return $serverRequest->withCookieParams($_COOKIE)->withQueryParams($_GET)->withParsedBody($_POST)->withUploadedFiles(Util::normalizeFiles($_FILES));
 }
Example #2
0
 public function testAttributes()
 {
     $request1 = new ServerRequest('/', 'GET');
     $request2 = $request1->withAttribute('name', 'value');
     $request3 = $request2->withAttribute('other', 'otherValue');
     $request4 = $request3->withoutAttribute('other');
     $request5 = $request3->withoutAttribute('unknown');
     $this->assertNotSame($request2, $request1);
     $this->assertNotSame($request3, $request2);
     $this->assertNotSame($request4, $request3);
     $this->assertNotSame($request5, $request4);
     $this->assertEmpty($request1->getAttributes());
     $this->assertEmpty($request1->getAttribute('name'));
     $this->assertEquals('something', $request1->getAttribute('name', 'something'), 'Should return the default value');
     $this->assertEquals('value', $request2->getAttribute('name'));
     $this->assertEquals(['name' => 'value'], $request2->getAttributes());
     $this->assertEquals(['name' => 'value', 'other' => 'otherValue'], $request3->getAttributes());
     $this->assertEquals(['name' => 'value'], $request4->getAttributes());
 }