Closure
Closure
The Hazaar Closure Class.
This class is a wrapper around PHP's Closure class that allows for the serialization of closures. This is useful for storing closures in a database or transmitting them over a network.
It supports both standard closures and arrow functions (fn).
The class can serialize the closure code to a string and deserialize it back to a closure.
It also provides methods to invoke the closure, get its parameters, and fetch its code.
Properties
public $
public $
code
private string $code
registeredClasses
private array $registeredClasses
Methods
__construct
Closure constructor.
public __construct(\stdClass $function): void
Parameters
Parameter | Type | Description |
---|---|---|
$function | \stdClass | the closure or stdClass containing code to wrap |
__invoke
Invoke the wrapped closure with the given arguments.
public __invoke(): mixed
__toString
Get the closure code as a string.
public __toString(): string
__sleep
Prepare the object for serialization.
public __sleep(): void
__wakeup
Restore the object after deserialization.
public __wakeup(): void
getClosure
Get the wrapped closure.
public getClosure(): void
getCode
Get the code for the closure.
public getCode(): string
loadCodeFromString
Load closure code from a string and re-initialize the closure.
public loadCodeFromString(string $string): void
Parameters
Parameter | Type | Description |
---|---|---|
$string | string | the closure code as a string |
getParameters
Get the parameters of the closure.
public getParameters(): void
jsonSerialize
Serialize the closure to JSON.
public jsonSerialize(): void
registerClass
public registerClass(string $class): void
Parameters
Parameter | Type | Description |
---|---|---|
$class | string |
fetchCode
Fetch the code for the closure from its source file.
protected fetchCode(): string
Generated by Hazaar API Doc Generator on Wed, 25 Jun 2025 06:07:12 +0000