Файл: vendor/laravel/serializable-closure/src/SerializableClosure.php
Строк: 110
<?php
namespace LaravelSerializableClosure;
use Closure;
use LaravelSerializableClosureExceptionsInvalidSignatureException;
use LaravelSerializableClosureExceptionsPhpVersionNotSupportedException;
use LaravelSerializableClosureSerializersSigned;
use LaravelSerializableClosureSignersHmac;
class SerializableClosure
{
/**
* The closure's serializable.
*
* @var LaravelSerializableClosureContractsSerializable
*/
protected $serializable;
/**
* Creates a new serializable closure instance.
*
* @param Closure $closure
* @return void
*/
public function __construct(Closure $closure)
{
if (PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
$this->serializable = SerializersSigned::$signer
? new SerializersSigned($closure)
: new SerializersNative($closure);
}
/**
* Resolve the closure with the given arguments.
*
* @return mixed
*/
public function __invoke()
{
if (PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return call_user_func_array($this->serializable, func_get_args());
}
/**
* Gets the closure.
*
* @return Closure
*/
public function getClosure()
{
if (PHP_VERSION_ID < 70400) {
throw new PhpVersionNotSupportedException();
}
return $this->serializable->getClosure();
}
/**
* Create a new unsigned serializable closure instance.
*
* @param Closure $closure
* @return LaravelSerializableClosureUnsignedSerializableClosure
*/
public static function unsigned(Closure $closure)
{
return new UnsignedSerializableClosure($closure);
}
/**
* Sets the serializable closure secret key.
*
* @param string|null $secret
* @return void
*/
public static function setSecretKey($secret)
{
SerializersSigned::$signer = $secret
? new Hmac($secret)
: null;
}
/**
* Sets the serializable closure secret key.
*
* @param Closure|null $transformer
* @return void
*/
public static function transformUseVariablesUsing($transformer)
{
SerializersNative::$transformUseVariables = $transformer;
}
/**
* Sets the serializable closure secret key.
*
* @param Closure|null $resolver
* @return void
*/
public static function resolveUseVariablesUsing($resolver)
{
SerializersNative::$resolveUseVariables = $resolver;
}
/**
* Get the serializable representation of the closure.
*
* @return array
*/
public function __serialize()
{
return [
'serializable' => $this->serializable,
];
}
/**
* Restore the closure after serialization.
*
* @param array $data
* @return void
*
* @throws LaravelSerializableClosureExceptionsInvalidSignatureException
*/
public function __unserialize($data)
{
if (Signed::$signer && ! $data['serializable'] instanceof Signed) {
throw new InvalidSignatureException();
}
$this->serializable = $data['serializable'];
}
}