nazg / http-server-request-handler
类似PSR-15的HTTP服务器请求处理程序接口
0.6.0
2020-03-31 07:56 UTC
Requires
- hhvm: ^4.41
- facebook/hack-http-request-response-interfaces: ^0.3
- hhvm/hhvm-autoload: ^3.0
- hhvm/hsl: ^4.0
- hhvm/hsl-experimental: ^4.0
Requires (Dev)
- facebook/fbexpect: ^2.7
- hhvm/hacktest: ^2.0
- hhvm/hhast: ^4.0
README
Hack的PSR-15类似HTTP服务器请求处理程序接口
要求
HHVM 3.30.0及更高版本。
需要 hsl-experimental
安装
$ hhvm $(which composer) require nazg/http-server-request-handler
用法
Go语言风格
func middleware(next http.HandlerFunc) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { log.Printf("Hello World, %s", r.RequestURI) next.ServeHTTP(w, r) } }
针对Hack
<?hh // strict namespace Acme\Middleware; use type HH\Lib\Experimental\IO\WriteHandle; use type Facebook\Experimental\Http\Message\ResponseInterface; use type Facebook\Experimental\Http\Message\ServerRequestInterface; use type Nazg\Http\Server\MiddlewareInterface; use type Nazg\Http\Server\RequestHandlerInterface; final class ExampleMiddleware implements MiddlewareInterface { public function process( WriteHandle $writeHandle, ServerRequestInterface $request, RequestHandlerInterface $handler, ): ResponseInterface { return $handler->handle($write, $request); } }