PHPackages                             omega-mvc/serializable-closure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. omega-mvc/serializable-closure

ActivePackage[Parsing &amp; Serialization](/categories/parsing)

omega-mvc/serializable-closure
==============================

Serializable Closure is a PHP package that allows closures to be serialized and stored, enabling their safe use in persistent storage or across requests.

2.0.0(1mo ago)0271GPL-3.0PHPPHP ^8.4

Since Mar 26Pushed 1mo agoCompare

[ Source](https://github.com/omega-mvc/serializable-closure)[ Packagist](https://packagist.org/packages/omega-mvc/serializable-closure)[ Docs](https://omega-mvc.github.io)[ RSS](/packages/omega-mvc-serializable-closure/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

 [ ![Omega Logo](https://github.com/omega-mvc/omega-assets/raw/main/images/logo-omega.png) ](https://omega-mvc.github.io)

 Serializable Closure Package
==============================

[](#----serializable-closure-package)

 [Documentation](https://omega-mvc.github.io) | [Changelog](https://github.com/omega-mvc/omega-mvc.github.io/blob/main/README.md#changelog) | [Contributing](https://github.com/omega-mvc/omega/blob/main/CONTRIBUTING.md) | [Code Of Conduct](https://github.com/omega-mvc/omega/blob/main/CODE_OF_CONDUCT.md) | [License](https://github.com/omega-mvc/omega/blob/main/LICENSE)

Omega - Serializable Closure
============================

[](#omega---serializable-closure)

Overview
--------

[](#overview)

Omega - Serializable Closure is a powerful and flexible library designed to provide robust serialization capabilities for PHP closures. It addresses the inherent challenges of serializing closures, especially those with complex scopes and bound contexts, while also introducing enhanced security features through cryptographic signatures. This library is meticulously crafted to leverage modern PHP features and ensure the integrity and safety of your serializable closures.

Key Features
------------

[](#key-features)

- **Native Serialization:** Efficiently serializes closures using PHP's native mechanisms when cryptographic signatures are not required.
- **Signed Serialization (HMAC):** Implements secure serialization by generating and verifying HMAC (Hash-based Message Authentication Code) signatures for closure data. This ensures the integrity and authenticity of serialized closures, preventing tampering.
- **Anonymous Class Support:** Seamlessly handles the serialization and deserialization of anonymous classes used within closures.
- **PHP 8.4+ Modern Features:** Fully embraces modern PHP features including:
    - **Readonly Properties:** Leverages readonly properties where appropriate for improved immutability and thread safety.
    - **Native Types:** Employs strict native type hints for enhanced code clarity and robustness.
    - **`#[AllowDynamicProperties]`:** Utilizes this attribute for compatibility with dynamic property scenarios.
- **Customizable Variable Transformation:** Provides hooks (`transformUseVariablesUsing` and `resolveUseVariablesUsing`) to customize how closure's `use` variables are transformed during serialization and deserialization.
- **Advanced Reflection:** Employs a sophisticated `ReflectionClosure` to deeply analyze closure code, identify static variables, and extract necessary metadata for accurate serialization.

Requirements
------------

[](#requirements)

- **PHP 8.4+**

Installation
------------

[](#installation)

To install Omega - Serializable Closure, you can use Composer:

```
composer require omega-mvc/serializable-closure
```

Usage
-----

[](#usage)

### Native Serialization (Unsigned)

[](#native-serialization-unsigned)

For scenarios where cryptographic integrity is not a primary concern, you can use unsigned serialization.

```

```

### Signed Serialization (HMAC)

[](#signed-serialization-hmac)

For enhanced security, it's recommended to use signed serialization. This requires setting a secret key.

```
