spiral-packages/serializable-closure

Laravel Serializable Closure bridge for Spiral Framework

1.0.0 2022-09-13 12:35 UTC

This package is auto-updated.

Last update: 2024-10-30 01:59:40 UTC


README

PHP Latest Version on Packagist GitHub Tests Action Status Total Downloads

Requirements

Make sure that your server is configured with following PHP version and extensions:

  • PHP 8.1+
  • Spiral framework 3.0+

Installation

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.

Configuration

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',
];

Usage

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

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

License

The MIT License (MIT). Please see License File for more information.