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 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; }
<?php use Phly\Conduit\MiddlewarePipe; use Phly\Http\Server; // Decline static file requests back to the PHP built-in webserver if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) { return false; } chdir(__DIR__ . '/../'); $loader = (require_once 'vendor/autoload.php'); $loader->add('Application\\', 'src'); $loader->add('Sample\\', 'src'); Server::createServer(include 'app.php', $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES)->listen();