1780612407
markdown-ce187cedd84d14d7c03d139b8610ee65f19a0386
s:3159:"<h1>Serializable Closure</h1>
<p><a href="https://github.com/laravel/serializable-closure/actions"></p>
<img src="https://github.com/laravel/serializable-closure/workflows/tests/badge.svg" alt="Build Status">
<p></a>
<a href="https://packagist.org/packages/laravel/serializable-closure"></p>
<img src="https://img.shields.io/packagist/dt/laravel/serializable-closure" alt="Total Downloads">
<p></a>
<a href="https://packagist.org/packages/laravel/serializable-closure"></p>
<img src="https://img.shields.io/packagist/v/laravel/serializable-closure" alt="Latest Stable Version">
<p></a>
<a href="https://packagist.org/packages/laravel/serializable-closure"></p>
<img src="https://img.shields.io/packagist/l/laravel/serializable-closure" alt="License">
<p></a></p>
<h2>Introduction</h2>
<blockquote>
<p>This project is a fork of the excellent <a href="https://github.com/opis/closure">opis/closure: 3.x</a> package. At Laravel, we decided to fork this package as the upcoming version <a href="https://github.com/opis/closure">4.x</a> is a complete rewrite on top of the <a href="https://www.php.net/manual/en/book.ffi.php">FFI extension</a>. As Laravel is a web framework, and FFI is not enabled by default in web requests, this fork allows us to keep using the <code>3.x</code> series while adding support for new PHP versions.</p>
</blockquote>
<p>Laravel Serializable Closure provides an easy and secure way to <strong>serialize closures in PHP</strong>.</p>
<h2>Official Documentation</h2>
<h3>Installation</h3>
<blockquote>
<p><strong>Requires <a href="https://php.net/releases/">PHP 7.4+</a></strong></p>
</blockquote>
<p>First, install Laravel Serializable Closure via the <a href="https://getcomposer.org/">Composer</a> package manager:</p>
<pre><code class="language-bash">composer require laravel/serializable-closure</code></pre>
<h3>Usage</h3>
<p>You may serialize a closure this way:</p>
<pre><code class="language-php">use Laravel\SerializableClosure\SerializableClosure;

$closure = fn () =&gt; 'james';

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

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

echo $closure(); // james;</code></pre>
<h3>Caveats</h3>
<ol>
<li>Creating <strong>anonymous classes</strong> within closures is not supported.</li>
<li>Using attributes within closures is not supported.</li>
</ol>
<h2>Contributing</h2>
<p>Thank you for considering contributing to Serializable Closure! The contribution guide can be found in the <a href="https://laravel.com/docs/contributions">Laravel documentation</a>.</p>
<h2>Code of Conduct</h2>
<p>In order to ensure that the Laravel community is welcoming to all, please review and abide by the <a href="https://laravel.com/docs/contributions#code-of-conduct">Code of Conduct</a>.</p>
<h2>Security Vulnerabilities</h2>
<p>Please review <a href="https://github.com/laravel/serializable-closure/security/policy">our security policy</a> on how to report security vulnerabilities.</p>
<h2>License</h2>
<p>Serializable Closure is open-sourced software licensed under the <a href="LICENSE.md">MIT license</a>.</p>";