Make sure that your server is configured with following PHP version and extensions:
- PHP 8.1+
- Spiral framework 3.0+
You can install the package via composer:
composer require spiral-packages/serializable-closure
After package install you need to register bootloader from the package.
protected const LOAD = [
// ...
\Spiral\SerializableClosure\Bootloader\SerializableClosureBootloader::class,
];
Note If you are using
spiral-packages/discoverer
, you don't need to register bootloader by yourself.
The package configuration provides the ability to set up a secret key that the
Laravel\SerializableClosure\SerializableClosure
class will use for signing.
Create a file app/config/serializable-closure.php
.
Add the secret
parameters.
For example:
<?php
declare(strict_types=1);
return [
'secret' => 'secret-key',
];
Using with Spiral\Serializer\SerializerManager
.
For example:
use Spiral\Serializer\SerializerManager;
$manager = $this->container->get(SerializerManager::class);
$serializer = $manager->getSerializer('closure');
$result = $serializer->serialize($payload);
$result = $serializer->unserialize($payload);
Also, you can set closure to be the default serializer in the serializer
config file and use
Spiral\Serializer\SerializerInterface
.
Example:
// config serializer.php
return [
'default' => 'closure',
];
// usage
use Spiral\Serializer\SerializerInterface;
$serializer = $this->container->get(SerializerInterface::class);
$result = $serializer->serialize($payload);
$result = $serializer->unserialize($payload);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.