jeremeamia/superclosure
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
nikic/php-parser | v4.19.1 | - | BSD-3-Clause | prod | |
symfony/polyfill-php56 | v1.20.0 | 1.99 kB | MIT | prod |
The jeremeamia/superclosure is a highly functional PHP library that allows for the serialization of closures and anonymous functions. Despite PHP's default restrictions against serializing closures, the SuperClosure library makes this serialization not only possible but straightforward and efficient. Services such as Laravel, InterNations HTTP mock, Jumper and several others have incorporated SuperClosure into their projects.
Making use of SuperClosure is pretty straightforward. First, you need to install the composer package using the command composer require jeremeamia/superclosure
. Once installed, you can create a new object of Serializer
class and call methods serialize
and unserialize
to serialize and unserialize closures. Here is an example:
use SuperClosure\Serializer;
$serializer = new Serializer();
$greeting = 'Hello';
$hello = function ($name = 'World') use ($greeting) {
echo "{$greeting}, {$name}!\n";
};
$serialized = $serializer->serialize($hello);
$unserialized = $serializer->unserialize($serialized);
$unserialized('Jeremy');
In this example, $hello
function is serialized and unserialized. After unserialization, it's called with the argument 'Jeremy'.
The full documentation for the jeremeamia/superclosure package can be found in the README file on the GitHub repository page at https://github.com/jeremeamia/super_closure. The README contains detailed guidance on how to install and use the library, what features it supports, and known caveats to take into consideration when using the library. The examples of code usage are also provided.