elephox / http
Elephox HTTP 库。
v0.7.0
2022-10-21 15:39 UTC
Requires
- php: ^8.1 <8.3
- ext-mbstring: *
- elephox/collection: dev-develop
- elephox/files: dev-develop
- elephox/mimey: ^4.0
- elephox/oor: dev-develop
- elephox/stream: dev-develop
- elephox/support: dev-develop
- jetbrains/phpstorm-attributes: ^1.0
- dev-develop
- 0.9.0.x-dev
- 0.8.0.x-dev
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.3
- 0.4.0
- 0.4.0-alpha5
- 0.4.0-alpha4
- 0.4.0-alpha3
- 0.4.0-alpha2
- 0.4.0-alpha1
- 0.3.27
- v0.3.25
- v0.3.24
- v0.3.23
- v0.3.22
- v0.3.21
- v0.3.20
- v0.3.18
- v0.3.17
- v0.3.16
- v0.3.15
- v0.3.14
- v0.3.13
- v0.3.12
- v0.3.11
- v0.3.10
- v0.3.9
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.1
- dev-release/0.9
- dev-release/0.8
- dev-release/0.7
- dev-release/0.6.0
- dev-16-psr-20-clock
- dev-18-make-servicecollection-more-extensible
- dev-release/0.6
- dev-release/0.5
- dev-release/0.4
- dev-release/0.3
This package is auto-updated.
Last update: 2024-08-30 01:49:43 UTC
README
此模块由 Elephox 使用,用于处理 HTTP 消息。它提供了一系列功能,如解析传入的 HTTP 消息、创建输出的 HTTP 消息、解析和修改头部、cookies、查询参数、上传文件和 URL 解析。
示例
<?php use Elephox\Http\ServerRequestBuilder; use Elephox\Http\Url; use Elephox\Http\Cookie; use Elephox\Http\Response; use Elephox\Http\ResponseCode; use Elephox\Http\ResponseSender; use Elephox\Http\UrlScheme; $request = ServerRequestBuilder::fromGlobals(); $request->getUrl()->path; // '/requested/path' $newRequest = $request->with() ->header('X-Foo', 'bar') ->cookie(new Cookie('dough', 'choco')) ->requestUrl(Url::fromString('https://example.com/new/url')) ->get(); $response = Response::build() ->responseCode(ResponseCode::OK) ->htmlBody('<h1>Hello World</h1>') ->header('X-Foo', 'bar') ->get(); ResponseSender::sendResponse($response); // you can also pass a response builder object here $url = Url::fromString('https://[email protected]/with/query?foo=bar&baz=qux'); $url->path; // '/with/query' $url->query; // ['foo' => 'bar', 'baz' => 'qux'] $url->host; // 'example.com' $url->port; // null $url->scheme === UrlScheme::HTTPS; // true $url->scheme->getDefaultPort(); // 443 $url->scheme->getScheme(); // 'https' $url->user; // 'user' $url->pass; // null $url->fragment; // null