parable-php/http
Composer 安装命令:
composer require parable-php/http
包简介
Parable HTTP is a straight-forward Request/Response library
README 文档
README
Parable Http is a minimalist Http library used to receive requests and send responses. It is not a full implementation, offering just-enough functionality.
Install
Php 8.0+ and composer are required.
$ composer require parable-php/http
Usage
To create a Request object automatically from the server variables, use:
$request = RequestFactory::createFromServer();
To create a Request from scratch, use:
$request = new Request( 'GET', 'http://url.here/path?param=value' );
To set up a minimal response you want to send to the client:
$response = new Response(200, 'This is the body');
And to send it, use the Dispatcher:
$response = new Response(200, 'This is the body'); $dispatcher = new Dispatcher(); $dispatcher->dispatch($response);
This will send a response with stat
us code 200, with the body set as passed to the Response upon creation.
API
Request
getMethod(): string- returns GET, POST, etc.getUri(): Uri- return aUriobject representing the uri being requestedgetRequestUri(): ?string- the path of theUrigetProtocol(): string- the protocol used (i.e.HTTP/1.1)getProtocolVersion(): string- the version part of the protocol (i.e.1.1)getBody(): ?string- the body of the request, if anygetUser(): ?string- the username from the urigetPass(): ?string- the password from the uriisHttps(): bool- whether the request was made over https. This represents a 'best guess' based on multiple checksisMethod(string $method): bool- check whether the method matches$method
From the HasHeaders trait:
getHeader(string $header): ?string- get a single header by string,nullif non-existinggetHeaders(): string[]- get all headers
Response
getBody(): ?string- the body to be sentsetBody(string $body): void- set the body as a stringprependBody(string $content): void- prepend the value to the bodyappendBody(string $content): void- append the value to the bodygetContentType(): string- the content type (i.e.text/html,application/json)setContentType(string $contentType): void- set the content typegetProtocol(): string- the protocol to be sent with (i.e.HTTP/1.1)getProtocolVersion(): string- the protocol version (i.e.1.1)setProtocol(string $protocol): void- set the protocolsetHeaders(array $headers): void- set multiple headers, resettingaddHeaders(array $headers): void- add multiple headersaddHeader(string $header, string $value): void- add single header
From the HasHeaders trait:
getHeader(string $header): ?string- get a single header by string,nullif non-existinggetHeaders(): string[]- get all headers
From the HasStatusCode trait:
getStatusCode(): int- the status code to be sent (i.e.200)getStatusCodeText(): ?string- the status code text to be sent (i.e.OK)setStatusCode(int $statusCode): void- set the status code
Dispatcher
dispatch(Response $response): void- dispatch a Response, sending all its content as setdispatchAndTerminate(Response $response, int $exitCode = 0): void- dispatch a Response and terminate, i.e., ending program flow immediately afterwards
Contributing
Any suggestions, bug reports or general feedback is welcome. Use github issues and pull requests, or find me over at devvoh.com.
License
All Parable components are open-source software, licensed under the MIT license.
parable-php/http 适用场景与选型建议
parable-php/http 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 527 次下载、GitHub Stars 达 2, 最近一次更新时间为 2019 年 03 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「library」 「micro」 「response」 「request」 「parable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 parable-php/http 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 parable-php/http 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 parable-php/http 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
Anax htmlform module.
Micro Active Record library in PHP, support chain calls, events, and relations.
Onix Micro Framework
Inbox pattern process implementation for your Laravel Applications
PHP classes for database handling upon PDO
统计信息
- 总下载量: 527
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-03-24