钛码 / middleware-msgpack
此包已被放弃,不再维护。未建议替代包。
msgpack.org的PSR-7中间件
1.0.1
2017-10-09 17:54 UTC
Requires
- ext-msgpack: *
- psr/http-message-implementation: *
This package is auto-updated.
Last update: 2022-09-13 17:44:09 UTC
README
Msgpack打包器作为PSR-7中间件。它将打包所有响应体内容并设置新的Content-Type头
用法
Slim框架示例
<?php require 'vendor/autoload.php'; $body = new \Slim\Http\Body(fopen('php://temp', 'r+')); //empty body for new response, can be replaced with any other implementation of PSR-7 StreamInterface $config = [ 'config_dir' => __DIR__.'/config', 'settings' => [ 'displayErrorDetails' => true, 'logger' => [ 'name' => 'slim-app', 'path' => __DIR__ . '/../logs/app.log', ], ], ]; $app = new \Slim\App($config); $app->add(new \TitaniumCodes\Middleware\Msgpack($body, 'application/x-msgpack')); $app->get('/', function ($request, $response, $args) use($config) { return $response->withJson($config); }); $app->run();
TiSuit集成
配置 msgpack.php
<?php return [ 'body' => new \Slim\Http\Body(fopen('php://temp', 'r+')); 'content-type' => 'application/x-msgpack', ];
配置 suit.php
<?php return [ //... 'providers' => [ '\TitaniumCodes\Middleware\MsgpackProvider', //... ], 'middlewares' => [ 'msgpack_middleware', //... ], ];