narrowspark/http-message-util
最新稳定版本:v0.3.0
Composer 安装命令:
composer require narrowspark/http-message-util
包简介
This repository holds utility classes and constants to facilitate common operations of PSR-7.
README 文档
README
This repository holds utility classes and constants to facilitate common operations of PSR-7.
Each header class is named after the specific http header and has the following functions for parsing and signing.
Installation
$ composer require narrowspark/http-message-util
Use
Here's an example using the InteractsWithAcceptLanguage class:
<?php declare(strict_types=1); use Narrowspark\Http\Message\Util\InteractsWithAcceptLanguage; $request = new Request(); $request = $request->withHeader('Accept-Language', 'zh, en-us; q=0.8, en; q=0.6'); return InteractsWithAcceptLanguage::getLanguages($request); // => ['zh', 'en', 'en_US']
Here's an example using the InteractsWithAuthorization class:
<?php declare(strict_types=1); use Narrowspark\Http\Message\Util\InteractsWithAuthorization; $request = new Request(); $request = $request->withHeader('Authorization', 'Basic QWxhZGRpbjpPcGVuU2VzYW1l'); return InteractsWithAuthorization::getAuthorization($request); // => ['Basic', 'QWxhZGRpbjpPcGVuU2VzYW1l']
Here's an example using the InteractsWithContentTypes class:
<?php declare(strict_types=1); use Narrowspark\Http\Message\Util\InteractsWithContentTypes; $request = new Request(); $request = $request->withHeader('Content-Type', 'application/json, */*'); return InteractsWithContentTypes::isJson($request); // => true $request = $request->withHeader('X-Pjax', 'true'); return InteractsWithContentTypes::isPjax($request); // => true $request = $request->withHeader('X-Requested-With', 'XMLHttpRequest'); return InteractsWithContentTypes::isAjax($request); // => true
Here's an example using the HeaderUtils class:
<?php declare(strict_types=1); use Narrowspark\Http\Message\Util\HeaderUtils; return HeaderUtils::split("da, en-gb;q=0.8", ",;"); // => array(array('da'), array('en-gb', 'q=0.8')) or return HeaderUtils::combine(array(array("foo", "abc"), array("bar"))); // => array("foo" => "abc", "bar" => true) or return HeaderUtils::toString(array("foo" => "abc", "bar" => true, "baz" => "a b c"), ","); // => 'foo=abc, bar, baz="a b c"' or return HeaderUtils::quote('foo bar'); // => "foo bar" or return HeaderUtils::unquote('"foo bar"'); // => foo bar
Here's an example using the InteractsWithDisposition class:
<?php declare(strict_types=1); use Narrowspark\Http\Message\Util\InteractsWithDisposition; $response = InteractsWithDisposition::appendDispositionHeader(new Response(), InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html'); return $response->getHeaderLine('Content-Disposition'); // => attachment; filename=foo.html or return InteractsWithDisposition::makeDisposition(InteractsWithDisposition::DISPOSITION_ATTACHMENT, 'foo.html'); // => attachment; filename=foo.html
Testing
$ vendor/bin/phpunit
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Note: Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
License
The Narrowspark http-emitter is open-sourced software licensed under the MIT license
narrowspark/http-message-util 适用场景与选型建议
narrowspark/http-message-util 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.23k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2017 年 10 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「http」 「util」 「psr-7」 「psr7」 「http-message-util」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 narrowspark/http-message-util 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 narrowspark/http-message-util 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 narrowspark/http-message-util 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Camilo3rd's PHP Utils Library
repository php library
Collection of exception class and utilities
PHP-ClamAV library - to scan the file for viruses
Model of a web-based resource
Collection of methods that I or you usually use.
统计信息
- 总下载量: 23.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 30
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-26