terablaze / serializable-closure
Terablaze Serializable Closure provides an easy and secure way to serialize closures in PHP.
dev-master / 1.x-dev
2023-01-20 21:30 UTC
Requires
- php: ^7.3|^8.0
Requires (Dev)
- nesbot/carbon: ^2.61
- pestphp/pest: ^1.21.3
- phpstan/phpstan: ^1.8.2
- symfony/var-dumper: ^5.4.11
This package is auto-updated.
Last update: 2024-10-21 01:26:32 UTC
README
Introduction
This project is a fork laravel/serializable-closure package, which is a fork of the excellent opis/closure: 3.x package.
Terablaze Serializable Closure provides an easy and secure way to serialize closures in PHP.
Official Documentation
Installation
Requires PHP 7.4+
First, install Terablaze Serializable Closure via the Composer package manager:
composer require terablaze/serializable-closure
Usage
You may serialize a closure this way:
use Terablaze\SerializableClosure\SerializableClosure; $closure = fn () => 'james'; // Recommended SerializableClosure::setSecretKey('secret'); $serialized = serialize(new SerializableClosure($closure)); $closure = unserialize($serialized)->getClosure(); echo $closure(); // james;
Caveats
- Creating anonymous classes within closures is not supported.
- Using attributes within closures is not supported.
- Serializing closures on REPL environments such as Terablaze Repl is not supported.
License
Serializable Closure is open-sourced software licensed under the MIT license.