PHP code example of spiral-packages / serializable-closure

1. Go to this page and download the library: Download spiral-packages/serializable-closure library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

spiral-packages / serializable-closure example snippets


protected const LOAD = [
    // ...
    \Spiral\SerializableClosure\Bootloader\SerializableClosureBootloader::class,
];



declare(strict_types=1);

return [
    'secret' => 'secret-key',
];

use Spiral\Serializer\SerializerManager;

$manager = $this->container->get(SerializerManager::class); 
$serializer = $manager->getSerializer('closure');

$result = $serializer->serialize($payload);
$result = $serializer->unserialize($payload);

// 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);