Phly\Http\Server::createServer PHP Method

createServer() public static method

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
public static createServer ( callable $callback, array $server, array $query, array $body, array $cookies, array $files ) : static
$callback callable
$server array
$query array
$body array
$cookies array
$files array
return static
    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 static($callback, $request, $response);
    }

Usage Example

Example #1
0
 public function testEmitsHeadersWithMultipleValuesMultipleTimes()
 {
     $server = ['HTTP_HOST' => 'example.com', 'REQUEST_METHOD' => 'GET', 'REQUEST_URI' => '/foo/bar'];
     $callback = function ($req, $res) {
         $res = $res->withAddedHeader('Content-Type', 'text/plain');
         $res = $res->withAddedHeader('Set-Cookie', 'foo=bar; expires=Wed, 1 Oct 2014 10:30; path=/foo; domain=example.com');
         $res = $res->withAddedHeader('Set-Cookie', 'bar=baz; expires=Wed, 8 Oct 2014 10:30; path=/foo/bar; domain=example.com');
         return $res;
     };
     $server = Server::createServer($callback, $server, [], [], [], []);
     $server->listen();
     $this->assertContains('HTTP/1.1 200 OK', HeaderStack::stack());
     $this->assertContains('Content-Type: text/plain', HeaderStack::stack());
     $this->assertContains('Set-Cookie: foo=bar; expires=Wed, 1 Oct 2014 10:30; path=/foo; domain=example.com', HeaderStack::stack());
     $this->assertContains('Set-Cookie: bar=baz; expires=Wed, 8 Oct 2014 10:30; path=/foo/bar; domain=example.com', HeaderStack::stack());
     $stack = HeaderStack::stack();
     return $stack;
 }
All Usage Examples Of Phly\Http\Server::createServer