titaniumcodes / middleware-msgpack
This package is abandoned and no longer maintained.
No replacement package was suggested.
PSR-7 Middleware of msgpack.org
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 packer as PSR-7 middleware. It will pack all response body contents and set new Content-Type header
Usage
Slim framework example
<?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 integration
config msgpack.php
:
<?php return [ 'body' => new \Slim\Http\Body(fopen('php://temp', 'r+')); 'content-type' => 'application/x-msgpack', ];
config suit.php
:
<?php return [ //... 'providers' => [ '\TitaniumCodes\Middleware\MsgpackProvider', //... ], 'middlewares' => [ 'msgpack_middleware', //... ], ];