PluginProbe
Auto Alt Text / 2.8.2
Auto Alt Text v2.8.2
3.0.3 2.8.2 1.3.1 1.3.2 2.0.0 2.1.0 2.1.1 2.2.0 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.5.0 2.5.1 2.5.2 2.5.3 2.6.0 2.6.1 2.7.0 2.8.0 2.8.1 All 28 releases
auto-alt-text / vendor-prefixed / laravel / serializable-closure / src / SerializableClosure.php

SerializableClosure.php in Auto Alt Text 2.8.2, at vendor-prefixed/laravel/serializable-closure/src/SerializableClosure.php

119 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AATXT\Vendor\Laravel\SerializableClosure;
4
5 use Closure;
6 use AATXT\Vendor\Laravel\SerializableClosure\Exceptions\InvalidSignatureException;
7 use AATXT\Vendor\Laravel\SerializableClosure\Exceptions\PhpVersionNotSupportedException;
8 use AATXT\Vendor\Laravel\SerializableClosure\Serializers\Signed;
9 use AATXT\Vendor\Laravel\SerializableClosure\Signers\Hmac;
10 class SerializableClosure
11 {
12 /**
13 * The closure's serializable.
14 *
15 * @var \AATXT\Vendor\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 = \AATXT\Vendor\Laravel\SerializableClosure\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 \AATXT\Vendor\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 \AATXT\Vendor\Laravel\SerializableClosure\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 \AATXT\Vendor\Laravel\SerializableClosure\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 \AATXT\Vendor\Laravel\SerializableClosure\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 \AATXT\Vendor\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 }