benycode/slim-request-deserialize
最新稳定版本:v1.3.1
Composer 安装命令:
composer require benycode/slim-request-deserialize
包简介
Deserialize slim 4 requests with the Symfony Serializer
README 文档
README
Deserialize Slim 4 requests with the Symfony Serializer
Table of contents
Install
Via Composer
$ composer require benycode/slim-request-deserialize
Requires Slim 4.
Usage
create an entity class:
declare(strict_types=1); namespace App; final class RequestData { public string $username; public string $loginId; public string $publicKey; public function setUsername(string $username): self { $this->username = $username; return $this; } public function getUsername(): ?string { return $this ->username ; } public function setLoginId(string $loginId): self { $this->loginId = $loginId; return $this; } public function getLoginId(): ?string { return $this ->loginId ; } public function setPublicKey(string $publicKey): self { $this->publicKey = $publicKey; return $this; } public function getPublicKey(): ?string { return $this ->publicKey ; } }
add a Middlewares to route:
use BenyCode\Slim\RequestDeserialize\RequestDeserializeMiddleware; use Symfony\Component\Serializer\Encoder\JsonEncoder as DeserializeEncoder; use App\RequestData; $app = new \Slim\App(); $app->post('/api/any_end_point',function ($req, $res, $args) { }) ->add(new RequestDeserializeMiddleware([ RequestData::class, DeserializeEncoder::FORMAT, // json encoder, but you can choice xml, yaml, csv ])) ; $app->run();
use your deserialized data:
... public function __invoke( ServerRequestInterface $request, ResponseInterface $response ): ResponseInterface { $requestData = $request ->getAttribute('request_data') ; $requestData->getUsername(); // get the username $requestData->getLoginId(); // get the login id ... } ...
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2023-02-06