irfantoor / http
针对黑客的遵守Psr标准的HTTP套件
0.2.1
2021-02-18 16:51 UTC
Requires
- fig/http-message-util: ^1.1
- irfantoor/collection: ~3.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- irfantoor/test: ^0.7.6
Provides
- fig/http-messsage-util-implementation: ~1.1.5
- psr/http-factory-implementation: ~1.0.10
- psr/http-message-implementation: ~1.0.1
README
Irfan的Http包是一个黑客的Http套件,它实现了psr/http-factory、psr/http-message和fig/http-message-util,消除了验证部分,因此您可以对您的Web应用或站点进行漏洞审计,或者可以编写小的API或测试工具。
在尝试一些创新值(例如Http请求或响应等)时,您可以忘记验证的限制。
快速安装。
使用composer将其包含在您的包中。
$ composer require irfantoor/http
注意:此包预装了Irfan的引擎(irfantoor/engine)的最新版本。尽管在功能实现上遵循Psr合规性,尽管并非严格遵循验证参数等指南,但您仍然可以在需要Psr合规Http组件的任何包中使用IrfanTOOR\Http,具有测试或增强您自建Http客户端、物联网设备等协议的灵活性。
示例
以下是一个示例代码(您可以在示例文件夹中找到它)
<?php # use php -S localhost:8000 examples/hello.php require dirname(__DIR__) . "/vendor/autoload.php"; use IrfanTOOR\Http\ServerRequest; use IrfanTOOR\Http\Response; # Server request we have received $request = new ServerRequest(); # create a response to send $response = new Response(); $response = $response ->withHeader("Content-Type", "application/json") ->withHeader("Engine", "Engine One v1.0") ; # our simple router $path = ltrim(rtrim($request->getUri()->getPath(), '/'), '/'); $args = $path === "" ? [] : explode('/', $path); $action = $args[0] ?? "home"; # lets route switch($action) { case "home": $response->getBody()->write(json_encode("I'm home")); break; case "hello": $name = ucfirst($args[1] ?? "world"); $response->getBody()->write(json_encode("Hello " . $name . "!")); break; default: $response = $response ->withStatus(0, "the status quo") ->withProtocolVersion("2.0") ->withHeader("lib(rary)", "IrfanTOOR\Http 0.1") ; $response->getBody()->write(json_encode([ "status" => 404, "error" => "nothing found here!", ])); break; } # thats all folks! $response->send();