@@ -17,19 +17,29 @@ class SerializableClosure
17
17
*/
18
18
protected $ serializable ;
19
19
20
+ /**
21
+ * Checks if the Closure should be signed.
22
+ * If set to `null` it will be based on if a signer exists.
23
+ *
24
+ * @var bool|null
25
+ */
26
+ protected $ shouldSign ;
27
+
20
28
/**
21
29
* Creates a new serializable closure instance.
22
30
*
23
31
* @param \Closure $closure
24
32
* @return void
25
33
*/
26
- public function __construct (Closure $ closure )
34
+ public function __construct (Closure $ closure, ? bool $ shouldSign = null )
27
35
{
36
+ $ this ->shouldSign = $ shouldSign ;
37
+
28
38
if (\PHP_VERSION_ID < 70400 ) {
29
39
throw new PhpVersionNotSupportedException ();
30
40
}
31
41
32
- $ this ->serializable = Serializers \Signed::$ signer
42
+ $ this ->serializable = Serializers \Signed::$ signer && $ this -> shouldSign !== false
33
43
? new Serializers \Signed ($ closure )
34
44
: new Serializers \Native ($ closure );
35
45
}
@@ -106,6 +116,7 @@ public function __serialize()
106
116
{
107
117
return [
108
118
'serializable ' => $ this ->serializable ,
119
+ 'shouldSign ' => $ this ->shouldSign ,
109
120
];
110
121
}
111
122
@@ -119,7 +130,7 @@ public function __serialize()
119
130
*/
120
131
public function __unserialize ($ data )
121
132
{
122
- if (Signed::$ signer && ! $ data ['serializable ' ] instanceof Signed) {
133
+ if (Signed::$ signer && ( $ data [ ' shouldSign ' ] ?? null ) !== false && ! $ data ['serializable ' ] instanceof Signed) {
123
134
throw new InvalidSignatureException ();
124
135
}
125
136
0 commit comments