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
コード例 #1
0
ファイル: Server.php プロジェクト: AnnaCaraman/ding2
 /**
  * Create a Server instance
  *
  * Creates a server instance from the callback and the following
  * PHP environmental values:
  *
  * - server; typically this will be the $_SERVER superglobal
  * - query; typically this will be the $_GET superglobal
  * - body; typically this will be the $_POST superglobal
  * - cookies; typically this will be the $_COOKIE superglobal
  * - files; typically this will be the $_FILES superglobal
  *
  * @param callable $callback
  * @param array $server
  * @param array $query
  * @param array $body
  * @param array $cookies
  * @param array $files
  * @return self
  */
 public static function createServer(callable $callback, array $server, array $query, array $body, array $cookies, array $files)
 {
     $request = ServerRequestFactory::fromGlobals($server, $query, $body, $cookies, $files);
     $response = new Response();
     return new self($callback, $request, $response);
 }
コード例 #2
0
 public function testCanCreateServerRequestViaFromGlobalsMethod()
 {
     $server = ['SERVER_PROTOCOL' => '1.1', 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'application/json', 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/foo/bar', 'QUERY_STRING' => 'bar=baz'];
     $cookies = $query = $body = $files = ['bar' => 'baz'];
     $cookies['cookies'] = true;
     $query['query'] = true;
     $body['body'] = true;
     $files = ['files' => ['tmp_name' => 'php://temp', 'size' => 0, 'error' => 0, 'name' => 'foo.bar', 'type' => 'text/plain']];
     $expectedFiles = ['files' => new UploadedFile('php://temp', 0, 0, 'foo.bar', 'text/plain')];
     $request = ServerRequestFactory::fromGlobals($server, $query, $body, $cookies, $files);
     $this->assertInstanceOf('Phly\\Http\\ServerRequest', $request);
     $this->assertEquals($cookies, $request->getCookieParams());
     $this->assertEquals($query, $request->getQueryParams());
     $this->assertEquals($body, $request->getParsedBody());
     $this->assertEquals($expectedFiles, $request->getUploadedFiles());
     $this->assertEmpty($request->getAttributes());
 }
コード例 #3
0
 public function testCanCreateServerRequestViaFromGlobalsMethod()
 {
     $server = ['SERVER_PROTOCOL' => '1.1', 'HTTP_HOST' => 'example.com', 'HTTP_ACCEPT' => 'application/json', 'REQUEST_METHOD' => 'POST', 'REQUEST_URI' => '/foo/bar', 'QUERY_STRING' => 'bar=baz'];
     $cookies = $query = $body = $files = ['bar' => 'baz'];
     $cookies['cookies'] = true;
     $query['query'] = true;
     $body['body'] = true;
     $files['files'] = true;
     $request = ServerRequestFactory::fromGlobals($server, $query, $body, $cookies, $files);
     $this->assertInstanceOf('Phly\\Http\\ServerRequest', $request);
     $this->assertEquals($cookies, $request->getCookieParams());
     $this->assertEquals($query, $request->getQueryParams());
     $this->assertEquals($body, $request->getParsedBody());
     $this->assertEquals($files, $request->getFileParams());
     $this->assertEmpty($request->getAttributes());
 }
コード例 #4
0
ファイル: Http.php プロジェクト: somos/framework
 public function __invoke()
 {
     return [\Phly\Http\ServerRequest::class => \DI\factory(function () {
         return \Phly\Http\ServerRequestFactory::fromGlobals();
     })];
 }