dmt-software/aura-web-psr
Composer 安装命令:
composer require dmt-software/aura-web-psr
包简介
PSR-7 wrapper for Aura.Web implementations
README 文档
README
Introduction
Aura.Web implementations do not follow PSR-7, the recommendation for HTTP messages. As more and more packages that solve common HTTP message problems do implement this recommendation, it would be nice if these can be used for Aura.Web implementations too. This package will allow you to start implementing PSR-7 without changing the library underneath, preserving the current code usage 1 to make migration or refactoring easier.
Installation
Although Aura.Web still supports down to PHP 5.3, this package needs PHP 7.0 or higher. Older implementations need to migrate to PHP 7 before this package can be used. I would suggest to use rector/rector to make this upgrade a more simple task.
Using composer
composer require dmt-software/aura-web-psr
Usage
Creating a ServerRequest
use DMT\Aura\Psr\Message\ServerRequest; // creating a request from $_SERVER variable $serverRequest = new ServerRequest( $_SERVER['REQUEST_METHOD'] ?? 'GET', $_SERVER['REQUEST_URI'] ?? '/', $_SERVER );
Handling uploaded files
use DMT\Aura\Psr\Factory\UploadedFileFactory; use DMT\Aura\Psr\Message\ServerRequest; use DMT\Aura\Psr\Message\UploadedFile; /** @var ServerRequest $serverRequest */ $serverRequest = $serverRequest->withUploadedFiles( /** @var UploadedFileFactory $uploadedFileFactory */ $uploadedFileFactory->createUploadedFilesFromGlobalFiles($_FILES) ); // at some later point foreach ($serverRequest->getUploadedFiles() as $uploadedFile) { /** @var UploadedFile $uploadedFile */ if ($uploadedFile->getError() === \UPLOAD_ERR_OK) { // ... process the uploaded file } }
Creating a Response
use DMT\Aura\Psr\Message\Response; $response = new Response(200, 'Ok'); $response->getBody()->write(/** your response html */);
Usage during migration
Wrapped objects
All PSR-7 http-messages wrap an Aura.Web object. According to their responsibility this can be any of the request or
response objects. These objects can be retrieved by calling the getInnerObject() method on the http-message.
use DMT\Aura\Psr\Message\ServerRequest; $serverRequest = new ServerRequest( $_SERVER['REQUEST_METHOD'] ?? 'GET', $_SERVER['REQUEST_URI'] ?? '/', $_SERVER ); $request = $serverRequest->getInnerObject(); // somewhere within the "legacy" code if ($request->isPost()) { // process post data }
Immutability
Changes to the http-messages will be internally tracked by the wrapped objects, but in such a way that the immutability of the message is preserved. This means each change that is made to a message object will return a new Aura.Web object instance.
use DMT\Aura\Psr\Message\ServerRequest; /** @var ServerRequest $serverRequest */ $auraRequest = $serverRequest->getInnerObject(); // new server request is returned with a fresh Aura.Web request $serverRequest = $serverRequest->withProtocolVersion('2'); $newAuraRequest = $serverRequest->getInnerObject(); if ($auraRequest->server->get('SERVER_PROTOCOL') != $newAuraRequest->server->get('SERVER_PROTOCOL')) { print 'Protocol version has changed'; }
Make sure each time a http-message is changed, the aura request must be retrieved from the new message instance too.
Incompatibility
Some build in solutions, like uploading files, receiving a json post, etc are not available when this package is used. For an overview of how to cope with these discrepancies see the compatibility documentation.
That http-messages use (a part of) the Aura.Web objects does not mean it is true the other way around. Some aura objects are not managed by the http-messages. For managing these objects one can fallback to the original code (once the inner object is retrieved) or use/write some additional code that works similar. See the workarounds documentation for tips and tricks on this subject.
dmt-software/aura-web-psr 适用场景与选型建议
dmt-software/aura-web-psr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 dmt-software/aura-web-psr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dmt-software/aura-web-psr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 8
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-15