Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Serializable Closure Laravel Package

laravel/serializable-closure

Securely serialize and unserialize PHP closures with Laravel’s fork of opis/closure 3.x, updated for modern PHP without requiring FFI. Wrap closures in SerializableClosure, set a secret key for signing, serialize safely, then restore with getClosure().

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Event-Driven Architecture: Enables serialization of closures for event listeners, job queues (e.g., Laravel Queues), or observer patterns, ensuring stateful logic persists across requests or processes.
  • Caching Complex Logic: Store closures (e.g., dynamic validation rules, custom transformations) in cache (e.g., Redis) for reuse without redefining them, reducing redundant computations.
  • Delayed Execution: Serialize closures to defer execution (e.g., scheduled tasks, cron jobs) while preserving context (e.g., captured variables).
  • API/GraphQL Resolvers: Serialize closures for dynamic field resolvers or middleware logic, enabling runtime configuration without hardcoding.
  • Build vs. Buy: Buy for teams needing closure serialization without reinventing the wheel. Avoid custom solutions unless requiring niche features (e.g., FFI-based serialization).
  • Roadmap Prioritization:
    • Short-term: Integrate into caching layers (e.g., Laravel’s cache drivers) for performance-critical paths.
    • Long-term: Explore use cases in Laravel’s core (e.g., serializing queue jobs with closures) or third-party packages (e.g., Spatie’s media library for dynamic processing).

When to Consider This Package

  • Adopt if:

    • Your app relies on serializing closures (e.g., for queues, caching, or delayed execution) and needs security (signed closures) or PHP 7.4+ compatibility.
    • You’re using Laravel and want a maintained fork of opis/closure (avoiding FFI dependency).
    • Closures contain modern PHP features (e.g., named arguments, attributes, enums) that older libraries don’t support.
    • You need debugging-friendly serialization (e.g., clear error messages for unsupported syntax).
  • Look elsewhere if:

    • You require FFI-based serialization (e.g., for extreme performance) and can enable the extension.
    • Your closures are trivial (e.g., fn() => 1) and don’t need serialization.
    • You’re in a REPL environment (e.g., Tinker) where serialization is unsupported.
    • Your team lacks PHP 7.4+ support or prefers a non-Laravel-maintained package.

How to Pitch It (Stakeholders)

For Executives: "This package lets us safely serialize closures—think of them as 'lambdas in a bottle'—to cache complex logic, queue delayed tasks, or dynamically configure systems without rewriting code. It’s battle-tested by Laravel, supports modern PHP, and avoids risky FFI dependencies. For example, we could cache user-specific validation rules or queue background jobs with context-aware closures, cutting redundant computations and improving scalability. Low risk (MIT license, active maintenance), high reward for performance-critical paths."

For Engineers: *"Laravel’s serializable-closure is a drop-in solution for serializing closures securely (with optional signing) and efficiently. Key benefits:

  • Works with modern PHP: Named args, attributes, enums, and PHP 8.5+.
  • Laravel-optimized: Forked from opis/closure to avoid FFI, with fixes for Laravel-specific edge cases (e.g., migrations, Bus::chain).
  • Battle-tested: Used in Laravel’s ecosystem; active maintenance with clear docs.
  • Use cases: Queue jobs, cached dynamic logic, event listeners, or API resolvers. Tradeoff: Slightly higher memory usage than FFI, but no extension dependency. Ready to integrate via Composer—just set a secret key and wrap closures in SerializableClosure."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony