smmehdisharifi/laravel-msgpack 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

smmehdisharifi/laravel-msgpack

最新稳定版本:1.0.0

Composer 安装命令:

composer require smmehdisharifi/laravel-msgpack

包简介

Laravel integration for MessagePack

README 文档

README

Latest Version on Packagist Total Downloads Tests

Laravel Msgpack brings MessagePack support to Laravel for fast and compact binary data serialization.
It adds encoding/decoding utilities, response macros, and a middleware for API requests and responses using Msgpack.

🚀 Features

  • Encode/Decode any PHP/Laravel data
  • response()->msgpack() macro like response()->json()
  • msgpack middleware to auto-handle request/response
  • Easy Laravel integration via Service Provider
  • Works with Laravel >= 9.x

📚 Table of Contents

🧰 Requirements

  • PHP 8.1 or higher
  • Laravel 9.x or newer

📦 Installation

composer require smmehdisharifi/laravel-msgpack

Requires PHP 8.1+ and Laravel 9.x or newer

⚙️ Configuration (Optional)

If you want to publish the config file:

php artisan vendor:publish --tag=msgpack-config

🧠 Basic Usage

Encode / Decode

use Msgpack;

$data = ['name' => 'Laravel', 'type' => 'framework'];

$packed = Msgpack::encode($data);
$unpacked = Msgpack::decode($packed);

Response Macro

return response()->msgpack([
    'message' => 'Hello from Msgpack!',
]);

Sends a binary response with header:

Content-Type: application/x-msgpack

Middleware

Register middleware in app/Http/Kernel.php:

protected $middlewareAliases = [
    'msgpack' => \SmMehdiSharifi\LaravelMsgpack\Middleware\MsgpackMiddleware::class,
];

Apply it to routes:

Route::middleware('msgpack')->post('/api/data', function (Request $request) {
    return response()->msgpack(['received' => $request->all()]);
});

🧪 Testing

This package includes PHPUnit tests using Orchestra Testbench. To run tests:

composer install
./vendor/bin/phpunit

📄 License

This package is open-sourced software licensed under the MIT license.

✨ Credits

Made with ❤️ by Mehdi Sharifi

Inspired by Laravel’s elegant API response system.

🤝 Contributing

Feel free to fork this repo and submit pull requests.

  • Found a bug? Open an issue
  • Have a feature idea? Let’s discuss it!
  • PRs with tests are welcome 🙌

📦 Packagist

View on Packagist:
https://packagist.org/packages/smmehdisharifi/laravel-msgpack

统计信息

  • 总下载量: 21
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固