mjohann/call-morph
最新稳定版本:v1.1.0
Composer 安装命令:
composer require mjohann/call-morph
包简介
CallMorph is a PHP class that simplifies and secures the serialization of anonymous functions by automatically selecting the appropriate library based on the PHP version, with support for a secret key when using Laravel's Serializable Closures.
README 文档
README
CallMorph is a PHP class that provides a simple and secure interface for serializing and unserializing anonymous functions (Closures). It automatically detects the PHP version and uses the appropriate library for maximum compatibility and security, including support for a secret key when using Laravel's Serializable Closures.
📦 Installation
You can install the library via Packagist/Composer:
composer require mjohann/call-morph
⚙️ Requirements
- PHP 7.0 or higher
- For PHP >= 8.1: laravel/serializable-closure must be installed.
- For PHP < 8.1: opis/closure is required.
🚀 Features
- Serialize and unserialize Closures with automatic compatibility based on PHP version
- Supports secret key configuration for secure serialization in Laravel
- Simple and clean API
Available Methods
__construct(string $secret)getSecret(): stringsetSecret(string $secret): voidserialize(Closure $callback): stringunserialize(string $callback): Closure
🧪 Usage Example
Publisher
<?php use MJohann\Packlib\CallMorph; require_once "vendor/autoload.php"; $name = "Johann"; $closure = function () use ($name) { sleep(1); return "My name is " . $name . " - Rand: " . rand(0, 999); }; $cm = new CallMorph("secret"); $serialized = $cm->serialize($closure); echo "CallMorph->serialize", PHP_EOL; var_dump($serialized); echo PHP_EOL, PHP_EOL; echo "CallMorph->unserialize", PHP_EOL; $closure = $cm->unserialize($serialized); echo $closure();
For more examples, see the example/ file in the repository.
📁 Project Structure
call-morph/
├── src/
│ └── CallMorph.php
│ └── Facades/
│ └── CallMorph.php
├── example/
│ └── script.php
├── composer.json
├── .gitignore
├── LICENSE
└── README.md
📄 License
This project is licensed under the MIT License. See the LICENSE file for more information.
👨💻 Author
Developed by Matheus Johann Araújo – Pernambuco, Brazil.
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-22