-
-
Notifications
You must be signed in to change notification settings - Fork 0
Defer
This class MUST be used to manage deferred callbacks that SHALL be executed at the end of a scope.
It provides mechanisms to register, execute, and report errors for callbacks in a LIFO order.
- Full name:
\FastForward\Defer\Defer - This class is marked as final and can't be subclassed
- This class implements:
\FastForward\Defer\DeferInterface - This class is a Final class
Constructs a new Defer instance and optionally registers an initial callback.
public __construct(callable|null $callback = null, mixed $arguments): mixedParameters:
| Parameter | Type | Description |
|---|---|---|
$callback |
callable|null | the initial callback to register (optional) |
$arguments |
mixed | Arguments for the callback. |
Executes all registered callbacks when the object is destroyed.
public __destruct(): mixedRegisters a callback to be executed later.
public __invoke(callable $callback, mixed $arguments): voidThis method MUST add the callback to the stack. It MAY be called multiple times.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$callback |
callable | the callback to register |
$arguments |
mixed | Arguments for the callback. |
Returns the number of registered callbacks.
public count(): intReturn Value:
the number of callbacks
Registers a callback to be executed later.
public defer(callable $callback, mixed $args): voidThis method MUST add the callback to the stack. It MAY be called multiple times.
Parameters:
| Parameter | Type | Description |
|---|---|---|
$callback |
callable | the callback to register |
$args |
mixed | Arguments for the callback. |
Determines if there are no registered callbacks.
public isEmpty(): boolReturn Value:
true if no callbacks are registered; otherwise, false
Sets the global error reporter for all Defer instances.
public static setErrorReporter(\FastForward\Defer\ErrorReporterInterface|null $reporter): void- This method is static. Parameters:
| Parameter | Type | Description |
|---|---|---|
$reporter |
\FastForward\Defer\ErrorReporterInterface|null | the error reporter to use |