Given a callback, takes an incoming request, dispatches it to the callback, and then sends a response.
예제 #1
0
 public function testListenPassesCallableArgumentToCallback()
 {
     $phpunit = $this;
     $invoked = false;
     $request = $this->request;
     $response = $this->response;
     $this->response->expects($this->once())->method('getHeaders')->will($this->returnValue([]));
     $final = function ($req, $res, $err = null) use($phpunit, $request, $response, &$invoked) {
         $phpunit->assertSame($request, $req);
         $phpunit->assertSame($response, $res);
         $invoked = true;
     };
     $callback = function ($req, $res, callable $final = null) use($phpunit) {
         if (!$final) {
             $phpunit->fail('No final callable passed!');
         }
         $final($req, $res);
     };
     $server = Server::createServerFromRequest($callback, $this->request, $this->response);
     $server->listen($final);
     $this->assertTrue($invoked);
 }
<?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();