Zend\Diactoros\ServerRequestFactory::fromGlobals PHP Method

fromGlobals() public static method

If any argument is not supplied, the corresponding superglobal value will be used. The ServerRequest created is then passed to the fromServer() method in order to marshal the request URI and headers.
See also: fromServer()
public static fromGlobals ( array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null ) : ServerRequest
$server array $_SERVER superglobal
$query array $_GET superglobal
$body array $_POST superglobal
$cookies array $_COOKIE superglobal
$files array $_FILES superglobal
return ServerRequest
    public static function fromGlobals(array $server = null, array $query = null, array $body = null, array $cookies = null, array $files = null)
    {
        $server = static::normalizeServer($server ?: $_SERVER);
        $files = static::normalizeFiles($files ?: $_FILES);
        $headers = static::marshalHeaders($server);
        return new ServerRequest($server, $files, static::marshalUriFromServer($server, $headers), static::get('REQUEST_METHOD', $server, 'GET'), 'php://input', $headers, $cookies ?: $_COOKIE, $query ?: $_GET, $body ?: $_POST, static::marshalProtocolVersion($server));
    }

Usage Example

Example #1
0
 /**
  * @test
  */
 public function datesAreReadFromQuery()
 {
     $shortCode = 'abc123';
     $this->visitsTracker->info($shortCode, new DateRange(null, new \DateTime('2016-01-01 00:00:00')))->willReturn([])->shouldBeCalledTimes(1);
     $response = $this->action->__invoke(ServerRequestFactory::fromGlobals()->withAttribute('shortCode', $shortCode)->withQueryParams(['endDate' => '2016-01-01 00:00:00']), new Response());
     $this->assertEquals(200, $response->getStatusCode());
 }
All Usage Examples Of Zend\Diactoros\ServerRequestFactory::fromGlobals