Fast Forward Deferred Callbacks utility classes

Defer

Table of Contents

Interfaces

DeferInterface
This interface MUST be implemented by any class that manages deferred callbacks.
ErrorReporterInterface
This interface MUST be implemented by any class that reports exceptions from deferred callbacks.

Classes

Defer
This class MUST be used to manage deferred callbacks that SHALL be executed at the end of a scope.
CompositeErrorReporter
Aggregates multiple error reporters and delegates error reporting to all of them.
ErrorLogErrorReporter
This error reporter implementation MUST log all reported exceptions using error_log.
NullErrorReporter
This error reporter implementation MUST ignore all reported exceptions.
PsrEventDispatcherErrorReporter
This error reporter implementation MUST dispatch all reported exceptions as events using a PSR-14 compatible event dispatcher.
PsrLoggerErrorReporter
This error reporter implementation MUST log all reported exceptions using a PSR-3 compatible logger.
DeferredCallbackFailed
Event representing a failed deferred callback execution.
LogDeferredCallbackFailure
Listener that logs failed deferred callback executions using a PSR-3 compatible logger.
DeferredCallbackListenerProvider
This provider MUST be used to supply listeners for DeferredCallbackFailed events.
DeferMiddleware
This middleware MUST be used to inject and manage a Defer instance in a PSR-15 ServerRequest.
CallbackDescriber
This utility class MUST be used to generate human-readable descriptions for any PHP callable.

Functions

defer()  : DeferInterface
Creates a new Defer instance, optionally registering a callback immediately.
using()  : mixed
Executes a callback within a controlled scope, ensuring resources are released at the end.
scope()  : mixed
Executes a callback within a deferred scope, ensuring all registered callbacks are executed at the end.

Functions

defer()

Creates a new Defer instance, optionally registering a callback immediately.

defer([callable|null $callback = null ], mixed ...$arguments) : DeferInterface

This function MUST return a DeferInterface implementation. If a callback is provided, it SHALL be registered.

Parameters
$callback : callable|null = null

the callback to register (optional)

$arguments : mixed

Arguments for the callback.

Return values
DeferInterface

the Defer instance

using()

Executes a callback within a controlled scope, ensuring resources are released at the end.

using(callable $factory, callable $callback) : mixed

This function MUST create a Defer instance, pass it to the factory, and execute the callback. The Defer instance SHALL be unset after execution.

Parameters
$factory : callable

a function that receives the Defer and returns the resource

$callback : callable

a function that receives the resource and executes the desired logic

Return values
mixed

the return value of the callback

scope()

Executes a callback within a deferred scope, ensuring all registered callbacks are executed at the end.

scope(callable $callback) : mixed

This function MUST create a Defer instance, pass it to the callback, and unset it after execution.

Parameters
$callback : callable

a function that receives the Defer and executes the desired logic

Return values
mixed

the return value of the callback


        
On this page

Search results