PluginProbe
Elementor Website Builder – more than just a page builder / 3.25.1
Elementor Website Builder – more than just a page builder v3.25.1
4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 All 455 releases
elementor / vendor_prefixed / laravel / serializable-closure / src / SerializableClosure.php

SerializableClosure.php in Elementor Website Builder – more than just a page builder 3.25.1, at vendor_prefixed/laravel/serializable-closure/src/SerializableClosure.php

120 lines 3.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ElementorDeps\Laravel\SerializableClosure;
4
5 use Closure;
6 use ElementorDeps\Laravel\SerializableClosure\Exceptions\InvalidSignatureException;
7 use ElementorDeps\Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
8 use ElementorDeps\Laravel\SerializableClosure\Serializers\Signed;
9 use ElementorDeps\Laravel\SerializableClosure\Signers\Hmac;
10 class SerializableClosure
11 {
12 /**
13 * The closure's serializable.
14 *
15 * @var \Laravel\SerializableClosure\Contracts\Serializable
16 */
17 protected $serializable;
18 /**
19 * Creates a new serializable closure instance.
20 *
21 * @param \Closure $closure
22 * @return void
23 */
24 public function __construct(Closure $closure)
25 {
26 if (\PHP_VERSION_ID < 70400) {
27 throw new PhpVersionNotSupportedException();
28 }
29 $this->serializable = Serializers\Signed::$signer ? new Serializers\Signed($closure) : new Serializers\Native($closure);
30 }
31 /**
32 * Resolve the closure with the given arguments.
33 *
34 * @return mixed
35 */
36 public function __invoke()
37 {
38 if (\PHP_VERSION_ID < 70400) {
39 throw new PhpVersionNotSupportedException();
40 }
41 return \call_user_func_array($this->serializable, \func_get_args());
42 }
43 /**
44 * Gets the closure.
45 *
46 * @return \Closure
47 */
48 public function getClosure()
49 {
50 if (\PHP_VERSION_ID < 70400) {
51 throw new PhpVersionNotSupportedException();
52 }
53 return $this->serializable->getClosure();
54 }
55 /**
56 * Create a new unsigned serializable closure instance.
57 *
58 * @param Closure $closure
59 * @return \Laravel\SerializableClosure\UnsignedSerializableClosure
60 */
61 public static function unsigned(Closure $closure)
62 {
63 return new UnsignedSerializableClosure($closure);
64 }
65 /**
66 * Sets the serializable closure secret key.
67 *
68 * @param string|null $secret
69 * @return void
70 */
71 public static function setSecretKey($secret)
72 {
73 Serializers\Signed::$signer = $secret ? new Hmac($secret) : null;
74 }
75 /**
76 * Sets the serializable closure secret key.
77 *
78 * @param \Closure|null $transformer
79 * @return void
80 */
81 public static function transformUseVariablesUsing($transformer)
82 {
83 Serializers\Native::$transformUseVariables = $transformer;
84 }
85 /**
86 * Sets the serializable closure secret key.
87 *
88 * @param \Closure|null $resolver
89 * @return void
90 */
91 public static function resolveUseVariablesUsing($resolver)
92 {
93 Serializers\Native::$resolveUseVariables = $resolver;
94 }
95 /**
96 * Get the serializable representation of the closure.
97 *
98 * @return array
99 */
100 public function __serialize()
101 {
102 return ['serializable' => $this->serializable];
103 }
104 /**
105 * Restore the closure after serialization.
106 *
107 * @param array $data
108 * @return void
109 *
110 * @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
111 */
112 public function __unserialize($data)
113 {
114 if (Signed::$signer && !$data['serializable'] instanceof Signed) {
115 throw new InvalidSignatureException();
116 }
117 $this->serializable = $data['serializable'];
118 }
119 }
120