PSR-7 middleware with https://msgpack.org
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.php_cs.dist
CODE_OF_CONDUCT.md
CONTRIBUTING.md
LICENSE
README.md
_config.yml
composer.json

README.md

PSR-7 Msgpack middleware

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',
        //...
    ],
];