PHP code example of next / http-server

1. Go to this page and download the library: Download next/http-server library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

next / http-server example snippets


class HttpKernel extends Kernel 
{
    // 全局中间件
    protected array $middlewares = [];
    
    // 注册路由
    protected function map(Router $router)
    {
        $router->get('/', 'IndexController@index');
    }
}

$kernel = \Next\Di\Context::getContainer->make(HttpKernel::class);

// 获取一个PsrServerRequest
$request = \Next\Http\Message\ServerRequest::createFromGlobals();

// 返回PsrResponse
$response = $kernel->handle($request);

// 发送响应
(new \Next\Http\Server\ResponseEmitter\FPMResponseEmitter())->emit($response);


(function() {
    $loader =  */
    $kernel   = Context::getContainer()->make(Kernel::class);
    $response = $kernel->handle(ServerRequest::createFromGlobals());
    (new FPMResponseEmitter())->emit($response);
})();