spiral-packages / serializable-closure
Laravel Serializable Closure bridge for Spiral Framework
Requires
- php: ^8.1
- laravel/serializable-closure: ^1.2
- spiral/boot: ^3.0
- spiral/serializer: ^3.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
- spiral/testing: ^2.0
- vimeo/psalm: ^4.20
This package is auto-updated.
Last update: 2024-11-30 02:10:58 UTC
README
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.