PluginProbe
The Innovative Form Builder – IvyForms / 0.2.1
The Innovative Form Builder – IvyForms v0.2.1
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / vendor / laravel / serializable-closure / src / Serializers / Signed.php

Signed.php in The Innovative Form Builder – IvyForms 0.2.1, at backend/vendor/laravel/serializable-closure/src/Serializers/Signed.php

92 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Laravel\SerializableClosure\Serializers;
4
5 use Laravel\SerializableClosure\Contracts\Serializable;
6 use Laravel\SerializableClosure\Exceptions\InvalidSignatureException;
7 use Laravel\SerializableClosure\Exceptions\MissingSecretKeyException;
8
9 class Signed implements Serializable
10 {
11 /**
12 * The signer that will sign and verify the closure's signature.
13 *
14 * @var \Laravel\SerializableClosure\Contracts\Signer|null
15 */
16 public static $signer;
17
18 /**
19 * The closure to be serialized/unserialized.
20 *
21 * @var \Closure
22 */
23 protected $closure;
24
25 /**
26 * Creates a new serializable closure instance.
27 *
28 * @param \Closure $closure
29 * @return void
30 */
31 public function __construct($closure)
32 {
33 $this->closure = $closure;
34 }
35
36 /**
37 * Resolve the closure with the given arguments.
38 *
39 * @return mixed
40 */
41 public function __invoke()
42 {
43 return call_user_func_array($this->closure, func_get_args());
44 }
45
46 /**
47 * Gets the closure.
48 *
49 * @return \Closure
50 */
51 public function getClosure()
52 {
53 return $this->closure;
54 }
55
56 /**
57 * Get the serializable representation of the closure.
58 *
59 * @return array
60 */
61 public function __serialize()
62 {
63 if (! static::$signer) {
64 throw new MissingSecretKeyException();
65 }
66
67 return static::$signer->sign(
68 serialize(new Native($this->closure))
69 );
70 }
71
72 /**
73 * Restore the closure after serialization.
74 *
75 * @param array $signature
76 * @return void
77 *
78 * @throws \Laravel\SerializableClosure\Exceptions\InvalidSignatureException
79 */
80 public function __unserialize($signature)
81 {
82 if (static::$signer && ! static::$signer->verify($signature)) {
83 throw new InvalidSignatureException();
84 }
85
86 /** @var \Laravel\SerializableClosure\Contracts\Serializable $serializable */
87 $serializable = unserialize($signature['serializable']);
88
89 $this->closure = $serializable->getClosure();
90 }
91 }
92