\SuperClosureSerializer

This is the serializer class used for serializing Closure objects.

We're abstracting away all the details, impossibilities, and scary things that happen within.

Summary

Methods
Properties
Constants
__construct()
serialize()
unserialize()
getData()
wrapClosures()
No public properties found
RECURSION
No protected methods found
No protected properties found
N/A
calculateSignature()
verifySignature()
$dataToKeep
$analyzer
$signingKey
N/A

Constants

RECURSION

RECURSION = "{{RECURSION}}" : string

The special value marking a recursive reference to a closure.

Properties

$dataToKeep

$dataToKeep : array

The keys of closure data required for serialization.

Type

array

$signingKey

$signingKey : string

The HMAC key to sign serialized closures.

Type

string

Methods

__construct()

__construct(\SuperClosure\Analyzer\ClosureAnalyzer|null  $analyzer = null, string|null  $signingKey = null) 

Create a new serializer instance.

Parameters

\SuperClosure\Analyzer\ClosureAnalyzer|null $analyzer

Closure analyzer instance.

string|null $signingKey

HMAC key to sign closure data.

serialize()

serialize(\Closure  $closure) : string

Takes a Closure object, decorates it with a SerializableClosure object, then performs the serialization.

Parameters

\Closure $closure

Closure to serialize.

Returns

string —

Serialized closure.

unserialize()

unserialize(string  $serialized) : \Closure

Takes a serialized closure, performs the unserialization, and then extracts and returns a the Closure object.

Parameters

string $serialized

Serialized closure.

Returns

\Closure —

Unserialized closure.

getData()

getData(\Closure  $closure, boolean  $forSerialization = false) : \Closure

Retrieves data about a closure including its code, context, and binding.

The data returned is dependant on the ClosureAnalyzer implementation used and whether the $forSerialization parameter is set to true. If $forSerialization is true, then only data relevant to serializing the closure is returned.

Parameters

\Closure $closure

Closure to analyze.

boolean $forSerialization

Include only serialization data.

Returns

\Closure

wrapClosures()

wrapClosures(mixed  $data, \SuperClosure\SerializerInterface  $serializer) 

Recursively traverses and wraps all Closure objects within the value.

NOTE: THIS MAY NOT WORK IN ALL USE CASES, SO USE AT YOUR OWN RISK.

Parameters

mixed $data

Any variable that contains closures.

\SuperClosure\SerializerInterface $serializer

The serializer to use.

calculateSignature()

calculateSignature(string  $data) : string

Calculates a signature for a closure's serialized data.

Parameters

string $data

Serialized closure data.

Returns

string —

Signature of the closure's data.

verifySignature()

verifySignature(string  $signature, string  $data) 

Verifies the signature for a closure's serialized data.

Parameters

string $signature

The provided signature of the data.

string $data

The data for which to verify the signature.

Throws

\SuperClosure\Exception\ClosureUnserializationException

if the signature is invalid.