项目
在 GitHub 查看
opis/closure
关于
序列化闭包、匿名类和任意数据
开发工具实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- -3
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文Opis Closure
Serialize closures and anonymous classes
Opis Closure is a PHP library that allows you to serialize closures, anonymous classes, and arbitrary data.
Key features:
- serialize closures (anonymous functions)
- serialize anonymous classes
- does not rely on PHP extensions (no FFI or similar dependencies)
- supports PHP 8.0-8.5 syntax
- handles circular references
- works with attributes
- works with readonly properties
- works with property hooks
- extensible via custom serializers and deserializers
- supports cryptographically signed data
- supports PHP's built-in SPL and Date classes, and the popular
nesbot/carbonpackage - reconstructed code is close to the original and debugger friendly
- and many more
Example of closure serialization
use function Opis\Closure\{serialize, unserialize};
$serialized = serialize(fn() => "hello from closure!");
$greet = unserialize($serialized);
echo $greet(); // hello from closure!
Example of anonymous class serialization
use function Opis\Closure\{serialize, unserialize};
$serialized = serialize(new class("hello from anonymous class!") {
public function __construct(private string $message) {}
public function greet(): string {
return $this->message;
}
});
$object = unserialize($serialized);
echo $object->greet(); // hello from anonymous class!
Migrating from 3.x
Version 4.x is a full rewrite of the library, but data deserialization from 3.x is possible. Read the docs on how to migrate from 3.x.
Documentation
The full documentation for this library can be found here.
License
Opis Closure is licensed under the MIT License (MIT).
Requirements
- PHP >= 8.0
Installation
Opis Closure is available on Packagist, and it can be installed from a command line interface by using Composer:
composer require opis/closure
Or you could directly reference it into your composer.json file as a dependency
{
"require": {
"opis/closure": "^4.5"
}
}
探索相关项目
加载中…