laravel/serializable-closure
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Laravel Serializable Closure is a potent and efficient tool used to serialize closures in PHP. This package is actually a fork of the popular opis/closure: 3.x package. Laravel forked this project to maintain usability with the 3.x
series and support newer PHP versions even when the FFI extension is not enabled by default in web requests, a common environment for Laravel, a web framework.
Using Laravel Serializable Closure relies on initial installation via Composer, the PHP package manager. Utilize the following command for installing:
composer require laravel/serializable-closure
After completing the installation, you can serialize a closure in the following manner:
use Laravel\SerializableClosure\SerializableClosure;
$closure = fn () => 'james';
// It is recommended to set a secret key
SerializableClosure::setSecretKey('secret');
$serialized = serialize(new SerializableClosure($closure));
$closure = unserialize($serialized)->getClosure();
echo $closure(); // Outputs 'james'
Please note a few caveats; for instance, creating anonymous classes within closures and using attributes within closures are not supported. Similarly, serializing closures on REPL environments like Laravel Tinker or closures that refer to objects with read-only properties are not supported.
The documentation for Laravel Serializable Closure can be found on the Laravel website. Also, this package's readme file on GitHub (https://github.com/laravel/serializable-closure.git) offers essential usage guidelines. For contributions, the guide can be found in the Laravel documentation. Similarly, for ensuring security vulnerabilities, please review the security policy of the Laravel Serializable Closure on its GitHub page.