wesmiler a41138daae wesmiler před 1 rokem
..
.github a41138daae wesmiler před 1 rokem
src a41138daae wesmiler před 1 rokem
tests a41138daae wesmiler před 1 rokem
.editorconfig a41138daae wesmiler před 1 rokem
.gitattributes a41138daae wesmiler před 1 rokem
.gitignore a41138daae wesmiler před 1 rokem
.styleci.yml a41138daae wesmiler před 1 rokem
CHANGELOG.md a41138daae wesmiler před 1 rokem
LICENSE.md a41138daae wesmiler před 1 rokem
README.md a41138daae wesmiler před 1 rokem
UPGRADE.md a41138daae wesmiler před 1 rokem
composer.json a41138daae wesmiler před 1 rokem
phpstan.neon a41138daae wesmiler před 1 rokem
phpunit.xml.dist a41138daae wesmiler před 1 rokem

README.md

Serializable Closure

<img src="https://github.com/laravel/serializable-closure/workflows/tests/badge.svg" alt="Build Status">

<img src="https://img.shields.io/packagist/dt/laravel/serializable-closure" alt="Total Downloads">

<img src="https://img.shields.io/packagist/v/laravel/serializable-closure" alt="Latest Stable Version">

<img src="https://img.shields.io/packagist/l/laravel/serializable-closure" alt="License">

Introduction

This project is a fork of the excellent opis/closure: 3.x package. At Laravel, we decided to fork this package as the upcoming version 4.x is a complete rewrite on top of the FFI extension. As Laravel is a web framework, and FFI is not enabled by default in web requests, this fork allows us to keep using the 3.x series while adding support for new PHP versions.

Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.

Official Documentation

Installation

Requires PHP 7.4+

First, install Laravel Serializable Closure via the Composer package manager:

composer require laravel/serializable-closure

Usage

You may serialize a closure this way:

use Laravel\SerializableClosure\SerializableClosure;

$closure = fn () => 'james';

// Recommended
SerializableClosure::setSecretKey('secret');

$serialized = serialize(new SerializableClosure($closure));
$closure = unserialize($serialized)->getClosure();

echo $closure(); // james;

Caveats

  • Anonymous classes cannot be created within closures.
  • Attributes cannot be used within closures.
  • Serializing closures on REPL environments like Laravel Tinker is not supported.
  • Serializing closures that reference objects with readonly properties is not supported.

Contributing

Thank you for considering contributing to Serializable Closure! The contribution guide can be found in the Laravel documentation.

Code of Conduct

In order to ensure that the Laravel community is welcoming to all, please review and abide by the Code of Conduct.

Security Vulnerabilities

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

License

Serializable Closure is open-sourced software licensed under the MIT license.