rancoud / http
Http 包
3.2.4
2024-09-02 11:39 UTC
Requires
- php: >=7.4.0
- ext-curl: *
- ext-mbstring: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16 || ^3.0
- phpunit/phpunit: ^9.2 || ^10.0 || ^11.0
- squizlabs/php_codesniffer: ^3.5
- symfony/process: ^5.2
Provides
README
高度基于 Nyholm 从 psr7 仓库的工作 Nyholm https://github.com/nyholm/psr7
Http 支持 PSR 7 15 17 18。
安装
composer require rancoud/http
如何使用它?
$factory = new Rancoud\Http\Message\Factory\Factory(); $request = $factory->createRequest('GET', 'https://example.com'); $stream = $factory->createStream('foobar');
客户端
方法
- sendRequest(request: RequestInterface): ResponseInterface
- setCAInfosPath([infos: string = null], [path: string = null]): self
- disableSSLVerification(): self
- enableSSLVerification(): self
工厂
方法
- createRequest(method: string, uri: mixed): RequestInterface
- createResponse([code: int = 200], [reasonPhrase: string = '']): ResponseInterface
- createResponseBody([code: int = 200], [body: mixed = null]): ResponseInterface
- createRedirection(location: string): ResponseInterface
- createStream([content: string = '']): StreamInterface
- createStreamFromFile(filename: string, [mode: string = 'r']): StreamInterface
- createStreamFromResource(resource: mixed): StreamInterface
- createUploadedFile(stream: StreamInterface, [size: int = null], [error: int = \UPLOAD_ERR_OK], [clientFilename: string = null], [clientMediaType: string = null]): UploadedFileInterface
- createUri([uri: string = '']): UriInterface
- createUriFromArray(server: array): UriInterface
- createServerRequest(method: string, uri: mixed, [serverParams: array = []]): ServerRequestInterface
- createServerRequestFromArray(server: array): ServerRequestInterface
- createServerRequestFromArrays(server: array, headers: array, cookie: array, get: array, post: array, files: array): ServerRequestInterface
- createServerRequestFromGlobals(): ServerRequestInterface
请求
构造函数
必填
可选
方法
- getBody(): StreamInterface
- getHeader(name: string): array
- getHeaderLine(name: string): string
- getHeaders(): array
- getMethod(): string
- getProtocolVersion(): string
- getRequestTarget(): string
- getUri(): UriInterface
- hasHeader(name: string): bool
- removeHeader(name: string): self
- addHeader(name: string, value: mixed): self
- withBody(body: StreamInterface): self
- withHeader(name: string, value: mixed): self
- withMethod(method: string): self
- withProtocolVersion(version: string): self
- withRequestTarget(requestTarget: string): self
- withUri(uri: UriInterface, [preserveHost: bool = false]): self
支持的 HTTP 方法
- ACL
- BASELINE-CONTROL
- BCOPY
- BDELETE
- BIND
- BMOVE
- BPROPFIND
- BPROPPATCH
- CHECKIN
- CHECKOUT
- CONNECT
- COPY
- DELETE
- GET
- HEAD
- LABEL
- LINK
- LOCK
- M-SEARCH
- MERGE
- MKACTIVITY
- MKCALENDAR
- MKCOL
- MKREDIRECTREF
- MKWORKSPACE
- MOVE
- NOTIFY
- OPTIONS
- ORDERPATCH
- PATCH
- POLL
- POST
- PRI
- PROPFIND
- PROPPATCH
- PURGE
- PUT
- REBIND
- REPORT
- SEARCH
- SUBSCRIBE
- TRACE
- UNBIND
- UNCHECKOUT
- UNLINK
- UNLOCK
- UNSUBSCRIBE
- UPDATE
- UPDATEREDIRECTREF
- VERSION-CONTROL
- VIEW
- X-MS-ENUMATTS
响应
构造函数
可选
方法
- getBody(): StreamInterface
- getHeader(name: string): array
- getHeaderLine(name: string): string
- getHeaders(): array
- getProtocolVersion(): string
- getReasonPhrase(): string
- getStatusCode(): int
- hasHeader(name: string): bool
- send([bodyChunkSize: int = 8192]): void
- withAddedHeader(name: string, value: mixed): self
- withBody(body: StreamInterface): self
- withHeader(name: string, value: mixed): self
- withoutHeader(name: string): self
- withProtocolVersion(version: string): self
- withStatus(code: int, [reasonPhrase: string = '']): self
支持的HTTP状态码和原因短语
- 100 => Continue
- 101 => 切换协议
- 102 => 处理中
- 103 => 提前提示
- 200 => OK
- 201 => 已创建
- 202 => 已接受
- 203 => 非授权信息
- 204 => 无内容
- 205 => 重置内容
- 206 => 部分内容
- 207 => 多状态
- 208 => 已报告
- 210 => 内容不同
- 226 => IM Used
- 300 => 多种选择
- 301 => 永久移动
- 302 => 已找到
- 303 => 看其他
- 304 => 未修改
- 305 => 使用代理
- 306 => 切换代理
- 307 => 临时重定向
- 308 => 永久重定向
- 310 => 重定向过多
- 400 => 错误请求
- 401 => 未授权
- 402 => 需要付费
- 403 => 禁止
- 404 => 未找到
- 405 => 不允许的方法
- 406 => 不可接受
- 407 => 需要代理身份验证
- 408 => 请求超时
- 409 => 冲突
- 410 => 已删除
- 411 => 长度必需
- 412 => 预先条件失败
- 413 => 负载过大
- 414 => URI过长
- 415 => 不支持媒体类型
- 416 => 范围未满足
- 417 => 期望失败
- 418 => 我是一把茶壶
- 421 => 请求错误
- 422 => 不可处理的实体
- 423 => 锁定
- 424 => 依赖失败
- 425 => 未排序的集合
- 426 => 需要升级
- 428 => 需要预先条件
- 429 => 请求过多
- 431 => 请求头字段过大
- 444 => 无响应
- 449 => 重试
- 450 => 被Windows家长控制阻止
- 451 => 由于法律原因不可用
- 456 => 不可恢复的错误
- 495 => SSL证书错误
- 496 => 需要SSL证书
- 497 => 将HTTP请求发送到HTTPS端口
- 499 => 客户端已关闭连接
- 500 => 内部服务器错误
- 501 => 未实现
- 502 => 网关错误
- 503 => 服务不可用
- 504 => 网关超时
- 505 => 不支持的HTTP版本
- 506 => 变体协商
- 507 => 存储不足
- 508 => 循环检测
- 509 => 带宽限制超出
- 510 => 未扩展
- 511 => 需要网络身份验证
- 520 => 未知错误
- 521 => Web服务器已关闭
- 522 => 连接超时
- 523 => 原始不可达
- 524 => 超时发生
- 525 => SSL握手失败
- 526 => 无效的SSL证书
- 527 => Railgun错误
- 599 => 网络连接超时错误
- 701 => Meh
- 702 => Emacs
- 703 => 爆炸
- 704 => GotoFail
- 705 => 我写了代码,但由于疏忽没有进行必要的验证(见795)
- 706 => 删除您的账户
- 707 => 不能退出vi
- 710 => PHP
- 711 => 便利店
- 712 => NoSQL
- 718 => 我不是茶壶
- 719 => Haskell
- 720 => 不可能的
- 721 => 已知未知
- 722 => 未知未知
- 723 => 令人困惑的
- 724 => 这行代码应该无法到达
- 725 => 在我的机器上它工作了
- 726 => 这是一个特性,不是一个错误
- 727 => 32位足够了
- 728 => 在我的时区里它工作了
- 730 => 该死的npm
- 731 => 该死的Rubygems
- 732 => 该死的Unic💩de
- 733 => 该死的死锁
- 734 => 破裂的延迟
- 735 => 破裂的IE
- 736 => 破裂的竞争条件
- 737 => 破裂的线程
- 739 => 破裂的Windows
- 740 => 案件有了智囊团。
- 750 => 没有麻烦去编译它
- 753 => 语法错误
- 754 => 分号太多
- 755 => 分号不足
- 756 => 过于不礼貌
- 757 => 过于礼貌
- 759 => 出现了意外的 "T_PAAMAYIM_NEKUDOTAYIM"
- 761 => 晕头转向
- 762 => 醉昏了头
- 763 => 咖啡因不足
- 764 => 咖啡因过多
- 765 => 铁轨营地
- 766 => 清醒的
- 767 => 醉酒的
- 768 => 在紧急关头不小心服用了安眠药而不是偏头痛药
- 771 => 缓存时间过长
- 772 => 缓存时间不足
- 773 => 完全未缓存
- 774 => 为什么会缓存这个?
- 775 => 没钱
- 776 => 异常上的错误
- 777 => 碰巧
- 778 => 差一个错误
- 779 => 差太多而无法计算的错误
- 780 => 项目所有者未响应
- 781 => 运营
- 782 => 质量保证
- 783 => 真的是客户请求
- 784 => 显然是管理层
- 785 => 没有附上TPS封面
- 786 => 现在试试
- 787 => 需要更多资金
- 788 => 设计师的最终设计不是这样的
- 789 => 不属于我的部门
- 791 => 因版权限制而关闭互联网
- 792 => 气候变化驱动的灾难性天气事件
- 793 => 肢尸末日
- 794 => 有人让PG接近REPL
- 795 => #heartbleed(见705)
- 796 => 一些DNS胡闹idno
- 797 => 这是互联网的最后一页。返回
- 798 => 我检查了数据库备份柜,柜子是空的
- 799 => 世界末日
ServerRequest
构造函数
必填
可选
方法
- getAttribute(name: string, [default: mixed = null]): mixed|null
- getAttributes(): array
- getBody(): StreamInterface
- getCookieParams(): array
- getHeader(name: string): array
- getHeaderLine(name: string): string
- getHeaders(): array
- getMethod(): string
- getParsedBody(): array|null|object
- getProtocolVersion(): string
- getQueryParams(): array
- getRequestTarget(): string
- getServerParams(): array
- getUploadedFiles(): array
- getUri(): UriInterface
- hasHeader(name: string): bool
- withAddedHeader(name: string, value: mixed): self
- withAttribute(name: string, value: mixed): self
- withBody(body: StreamInterface): self
- withCookieParams(cookies: array): self
- withHeader(name: string, value: mixed): self
- withMethod(method: string): self
- withoutAttribute(name: string): self
- withoutHeader(name: string): self
- withParsedBody(data: array|null|object): self
- withProtocolVersion(version: string): self
- withQueryParams(query: array): self
- withRequestTarget(requestTarget: string): self
- withUploadedFiles(uploadedFiles: array): self
- withUri(uri: UriInterface, [preserveHost: bool = false]): self
Stream
方法
- __destruct(): void
- __toString(): string
- close(): void
- detach(): null|resource
- eof(): bool
- getContents(): string
- getMetadata([key: string|null = null]): ?array
- getSize(): ?int
- isReadable(): bool
- isSeekable(): bool
- isWritable(): bool
- read(length: int): string
- rewind(): void
- seek(offset: int, [whence: int = \SEEK_SET]): void
- tell(): int
- write(string: string): bool|int
Static Methods
- create([content: string = '']): StreamInterface
UploadedFile
构造函数
必填
可选
方法
- getClientFilename(): ?string
- getClientMediaType(): ?string
- getError(): int
- getSize(): ?int
- getStream(): StreamInterface
- getFilename(): ?string
- moveTo(targetPath: string): void
支持的上传错误
- UPLOAD_ERR_OK
- UPLOAD_ERR_INI_SIZE
- UPLOAD_ERR_FORM_SIZE
- UPLOAD_ERR_PARTIAL
- UPLOAD_ERR_NO_FILE
- UPLOAD_ERR_NO_TMP_DIR
- UPLOAD_ERR_CANT_WRITE
- UPLOAD_ERR_EXTENSION
Uri
构造函数
可选
方法
- __toString(): string
- getAuthority(): string
- getFragment(): string
- getHost(): string
- getPath(): string
- getPort(): ?int
- getQuery(): string
- getScheme(): string
- getUserInfo(): string
- withFragment(fragment: string): self
- withHost(host: string): self
- withPath(path: string): self
- withPort(port: int|null): self
- withQuery(query: string): self
- withScheme(scheme: string): self
- withUserInfo(user: string, [password: string|null = null]): self
如何开发
composer ci
用于php-cs-fixer、phpunit和覆盖率
composer lint
用于php-cs-fixer
composer test
用于phpunit和覆盖率