FastForward Defer
fast-forward/defer
brings defer-style cleanup to PHP by tying callbacks to
object lifetime. A Defer
instance collects callbacks and runs them
automatically when the scope ends, which makes cleanup code easier to keep next
to acquisition code without losing predictable execution order.
The package is intentionally small. You get a concrete Defer
class, a
minimal DeferInterface
, three helper functions, pluggable error reporting,
PSR-15 middleware support, and a utility to describe callbacks for logs and
events.
Useful links
Highlights
- Scope-bound cleanup using direct instantiation or helper functions.
- LIFO execution, which keeps teardown order explicit and deterministic.
- Exception-safe callback execution: one failing callback does not stop the callback itself from being reported.
- Pluggable error reporters, including
error_log, PSR-3, PSR-14, and composite fan-out. - Request-scoped cleanup with
DeferMiddlewarefor PSR-15 applications. CallbackDescriberfor readable log and event context.
Contents:
- Getting Started
- Installation
- Usage
- Advanced Topics
- API Reference
- PSR Integrations
- Examples
- Links
-
FAQ
- When do deferred callbacks actually run?
- Why do callbacks run in reverse order?
- What happens if one deferred callback throws?
- Can a failing reporter stop the rest of the cleanup chain?
- Should I keep one Defer instance in a singleton or shared service?
- Can I inspect whether cleanup callbacks are pending?
- Does this package provide a PSR-11 service provider?
- How do I use it in a PSR-15 application?
- Can I listen to cleanup failures as PSR-14 events?
- What is CallbackDescriber for?
- Is using() required, or can I stay with plain Defer?
- Where should I start if I want a practical walkthrough?
- Compatibility