summaryrefslogtreecommitdiffstats
path: root/30.patch
blob: 751403d0de22555991c377e4bf5777a5bd9b4f2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
From 9d67308444c316788be6b5dff2c7493ea9cc1408 Mon Sep 17 00:00:00 2001
From: webimpress <contact@webimpress.com>
Date: Wed, 16 Oct 2019 10:15:32 +0100
Subject: [PATCH 1/2] Fix (un)serialization for Reflection* objects - PHP 7.4

Fixes #29
---
 src/Reflection/AbstractFunction.php    | 31 +++++++++++++++++++++++--
 src/Reflection/ReflectionClass.php     | 17 +++++++++++++-
 src/Reflection/ReflectionMethod.php    |  3 ++-
 src/Reflection/ReflectionParameter.php | 32 ++++++++++++++++++++++++++
 4 files changed, 79 insertions(+), 4 deletions(-)

diff --git a/src/Reflection/AbstractFunction.php b/src/Reflection/AbstractFunction.php
index f9adfc2e..2c2bcfa7 100644
--- a/src/Reflection/AbstractFunction.php
+++ b/src/Reflection/AbstractFunction.php
@@ -51,6 +51,12 @@ abstract class AbstractFunction
      */
     protected $class;
 
+    /**
+     * Function name (needed for serialization)
+     * @var string
+     */
+    protected $name;
+
     /**
      * Function/method description
      * @var string
@@ -109,6 +115,8 @@ public function __construct(ReflectionFunctionAbstract $r, $namespace = null, $a
             $this->class = $r->getDeclaringClass()->getName();
         }
 
+        $this->name = $r->getName();
+
         // Perform some introspection
         $this->reflect();
     }
@@ -438,6 +446,25 @@ public function getInvokeArguments()
         return $this->argv;
     }
 
+    /**
+     * @return string[]
+     */
+    public function __sleep()
+    {
+        $serializable = [];
+        foreach ($this as $name => $value) {
+            if ($value instanceof PhpReflectionFunction
+                || $value instanceof PhpReflectionMethod
+            ) {
+                continue;
+            }
+
+            $serializable[] = $name;
+        }
+
+        return $serializable;
+    }
+
     /**
      * Wakeup from serialization
      *
@@ -450,9 +477,9 @@ public function __wakeup()
     {
         if ($this->reflection instanceof PhpReflectionMethod) {
             $class = new PhpReflectionClass($this->class);
-            $this->reflection = new PhpReflectionMethod($class->newInstance(), $this->getName());
+            $this->reflection = new PhpReflectionMethod($class->newInstance(), $this->name);
         } else {
-            $this->reflection = new PhpReflectionFunction($this->getName());
+            $this->reflection = new PhpReflectionFunction($this->name);
         }
     }
 }
diff --git a/src/Reflection/ReflectionClass.php b/src/Reflection/ReflectionClass.php
index 02027965..c6cae995 100644
--- a/src/Reflection/ReflectionClass.php
+++ b/src/Reflection/ReflectionClass.php
@@ -42,6 +42,12 @@ class ReflectionClass
      */
     protected $reflection;
 
+    /**
+     * Reflection class name (needed for serialization)
+     * @var string
+     */
+    protected $name;
+
     /**
      * Constructor
      *
@@ -55,6 +61,7 @@ class ReflectionClass
     public function __construct(PhpReflectionClass $reflection, $namespace = null, $argv = false)
     {
         $this->reflection = $reflection;
+        $this->name = $reflection->getName();
         $this->setNamespace($namespace);
 
         foreach ($reflection->getMethods() as $method) {
@@ -171,6 +178,14 @@ public function setNamespace($namespace)
      */
     public function __wakeup()
     {
-        $this->reflection = new PhpReflectionClass($this->getName());
+        $this->reflection = new PhpReflectionClass($this->name);
+    }
+
+    /**
+     * @return string[]
+     */
+    public function __sleep()
+    {
+        return ['config', 'methods', 'namespace', 'name'];
     }
 }
diff --git a/src/Reflection/ReflectionMethod.php b/src/Reflection/ReflectionMethod.php
index 09a6857c..0b4e9483 100644
--- a/src/Reflection/ReflectionMethod.php
+++ b/src/Reflection/ReflectionMethod.php
@@ -58,6 +58,7 @@ public function __construct(ReflectionClass $class, \ReflectionMethod $r, $names
 
         // If method call, need to store some info on the class
         $this->class = $class->getName();
+        $this->name = $r->getName();
 
         // Perform some introspection
         $this->reflect();
@@ -88,7 +89,7 @@ public function __wakeup()
             $this->getNamespace(),
             $this->getInvokeArguments()
         );
-        $this->reflection = new \ReflectionMethod($this->classReflection->getName(), $this->getName());
+        $this->reflection = new \ReflectionMethod($this->classReflection->getName(), $this->name);
     }
 
     /**
diff --git a/src/Reflection/ReflectionParameter.php b/src/Reflection/ReflectionParameter.php
index 94fa9a1e..5bcec7be 100644
--- a/src/Reflection/ReflectionParameter.php
+++ b/src/Reflection/ReflectionParameter.php
@@ -37,6 +37,18 @@ class ReflectionParameter
      */
     protected $description;
 
+    /**
+     * Parameter name (needed for serialization)
+     * @var string
+     */
+    protected $name;
+
+    /**
+     * Declaring function name (needed for serialization)
+     * @var string
+     */
+    protected $functionName;
+
     /**
      * Constructor
      *
@@ -47,6 +59,13 @@ class ReflectionParameter
     public function __construct(\ReflectionParameter $r, $type = 'mixed', $description = '')
     {
         $this->reflection = $r;
+
+        // Store parameters needed for (un)serialization
+        $this->name = $r->getName();
+        $this->functionName = $r->getDeclaringClass()
+            ? [$r->getDeclaringClass()->getName(), $r->getDeclaringFunction()->getName()]
+            : $r->getDeclaringFunction()->getName();
+
         $this->setType($type);
         $this->setDescription($description);
     }
@@ -140,4 +159,17 @@ public function getPosition()
     {
         return $this->position;
     }
+
+    /**
+     * @return string[]
+     */
+    public function __sleep()
+    {
+        return ['position', 'type', 'description', 'name', 'functionName'];
+    }
+
+    public function __wakeup()
+    {
+        $this->reflection = new \ReflectionParameter($this->functionName, $this->name);
+    }
 }

From 70eb7e61fd562414d574e6300bd5d3741ed8e2ab Mon Sep 17 00:00:00 2001
From: webimpress <contact@webimpress.com>
Date: Wed, 16 Oct 2019 10:36:14 +0100
Subject: [PATCH 2/2] Changes properties to protected from private

private properties of abstract class cannot be serialized on PHP versions
prior to 7.4.

Changed these properties to protected so we don't need to do anything
extra on unserialization.
---
 src/Reflection/AbstractFunction.php | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/Reflection/AbstractFunction.php b/src/Reflection/AbstractFunction.php
index 2c2bcfa7..a1f551f1 100644
--- a/src/Reflection/AbstractFunction.php
+++ b/src/Reflection/AbstractFunction.php
@@ -81,11 +81,11 @@ abstract class AbstractFunction
      */
     protected $docComment = '';
 
-    private $return;
-    private $returnDesc;
-    private $paramDesc;
-    private $sigParams;
-    private $sigParamsDepth;
+    protected $return;
+    protected $returnDesc;
+    protected $paramDesc;
+    protected $sigParams;
+    protected $sigParamsDepth;
 
     /**
      * Constructor