1 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,359 +0,0 @@ |
1 |
-<?php |
|
2 |
- |
|
3 |
-/* |
|
4 |
- * This file is part of the Symfony package. |
|
5 |
- * |
|
6 |
- * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
- * |
|
8 |
- * For the full copyright and license information, please view the LICENSE |
|
9 |
- * file that was distributed with this source code. |
|
10 |
- */ |
|
11 |
- |
|
12 |
-namespace Symfony\Component\Debug\Exception; |
|
13 |
- |
|
14 |
-use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; |
|
15 |
-use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
16 |
- |
|
17 |
-/** |
|
18 |
- * FlattenException wraps a PHP Error or Exception to be able to serialize it. |
|
19 |
- * |
|
20 |
- * Basically, this class removes all objects from the trace. |
|
21 |
- * |
|
22 |
- * @author Fabien Potencier <fabien@symfony.com> |
|
23 |
- */ |
|
24 |
-class FlattenException |
|
25 |
-{ |
|
26 |
- private $message; |
|
27 |
- private $code; |
|
28 |
- private $previous; |
|
29 |
- private $trace; |
|
30 |
- private $traceAsString; |
|
31 |
- private $class; |
|
32 |
- private $statusCode; |
|
33 |
- private $headers; |
|
34 |
- private $file; |
|
35 |
- private $line; |
|
36 |
- |
|
37 |
- public static function create(\Exception $exception, $statusCode = null, array $headers = []) |
|
38 |
- { |
|
39 |
- return static::createFromThrowable($exception, $statusCode, $headers); |
|
40 |
- } |
|
41 |
- |
|
42 |
- public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self |
|
43 |
- { |
|
44 |
- $e = new static(); |
|
45 |
- $e->setMessage($exception->getMessage()); |
|
46 |
- $e->setCode($exception->getCode()); |
|
47 |
- |
|
48 |
- if ($exception instanceof HttpExceptionInterface) { |
|
49 |
- $statusCode = $exception->getStatusCode(); |
|
50 |
- $headers = array_merge($headers, $exception->getHeaders()); |
|
51 |
- } elseif ($exception instanceof RequestExceptionInterface) { |
|
52 |
- $statusCode = 400; |
|
53 |
- } |
|
54 |
- |
|
55 |
- if (null === $statusCode) { |
|
56 |
- $statusCode = 500; |
|
57 |
- } |
|
58 |
- |
|
59 |
- $e->setStatusCode($statusCode); |
|
60 |
- $e->setHeaders($headers); |
|
61 |
- $e->setTraceFromThrowable($exception); |
|
62 |
- $e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception)); |
|
63 |
- $e->setFile($exception->getFile()); |
|
64 |
- $e->setLine($exception->getLine()); |
|
65 |
- |
|
66 |
- $previous = $exception->getPrevious(); |
|
67 |
- |
|
68 |
- if ($previous instanceof \Throwable) { |
|
69 |
- $e->setPrevious(static::createFromThrowable($previous)); |
|
70 |
- } |
|
71 |
- |
|
72 |
- return $e; |
|
73 |
- } |
|
74 |
- |
|
75 |
- public function toArray() |
|
76 |
- { |
|
77 |
- $exceptions = []; |
|
78 |
- foreach (array_merge([$this], $this->getAllPrevious()) as $exception) { |
|
79 |
- $exceptions[] = [ |
|
80 |
- 'message' => $exception->getMessage(), |
|
81 |
- 'class' => $exception->getClass(), |
|
82 |
- 'trace' => $exception->getTrace(), |
|
83 |
- ]; |
|
84 |
- } |
|
85 |
- |
|
86 |
- return $exceptions; |
|
87 |
- } |
|
88 |
- |
|
89 |
- public function getStatusCode() |
|
90 |
- { |
|
91 |
- return $this->statusCode; |
|
92 |
- } |
|
93 |
- |
|
94 |
- /** |
|
95 |
- * @return $this |
|
96 |
- */ |
|
97 |
- public function setStatusCode($code) |
|
98 |
- { |
|
99 |
- $this->statusCode = $code; |
|
100 |
- |
|
101 |
- return $this; |
|
102 |
- } |
|
103 |
- |
|
104 |
- public function getHeaders() |
|
105 |
- { |
|
106 |
- return $this->headers; |
|
107 |
- } |
|
108 |
- |
|
109 |
- /** |
|
110 |
- * @return $this |
|
111 |
- */ |
|
112 |
- public function setHeaders(array $headers) |
|
113 |
- { |
|
114 |
- $this->headers = $headers; |
|
115 |
- |
|
116 |
- return $this; |
|
117 |
- } |
|
118 |
- |
|
119 |
- public function getClass() |
|
120 |
- { |
|
121 |
- return $this->class; |
|
122 |
- } |
|
123 |
- |
|
124 |
- /** |
|
125 |
- * @return $this |
|
126 |
- */ |
|
127 |
- public function setClass($class) |
|
128 |
- { |
|
129 |
- $this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class; |
|
130 |
- |
|
131 |
- return $this; |
|
132 |
- } |
|
133 |
- |
|
134 |
- public function getFile() |
|
135 |
- { |
|
136 |
- return $this->file; |
|
137 |
- } |
|
138 |
- |
|
139 |
- /** |
|
140 |
- * @return $this |
|
141 |
- */ |
|
142 |
- public function setFile($file) |
|
143 |
- { |
|
144 |
- $this->file = $file; |
|
145 |
- |
|
146 |
- return $this; |
|
147 |
- } |
|
148 |
- |
|
149 |
- public function getLine() |
|
150 |
- { |
|
151 |
- return $this->line; |
|
152 |
- } |
|
153 |
- |
|
154 |
- /** |
|
155 |
- * @return $this |
|
156 |
- */ |
|
157 |
- public function setLine($line) |
|
158 |
- { |
|
159 |
- $this->line = $line; |
|
160 |
- |
|
161 |
- return $this; |
|
162 |
- } |
|
163 |
- |
|
164 |
- public function getMessage() |
|
165 |
- { |
|
166 |
- return $this->message; |
|
167 |
- } |
|
168 |
- |
|
169 |
- /** |
|
170 |
- * @return $this |
|
171 |
- */ |
|
172 |
- public function setMessage($message) |
|
173 |
- { |
|
174 |
- if (false !== strpos($message, "class@anonymous\0")) { |
|
175 |
- $message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { |
|
176 |
- return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; |
|
177 |
- }, $message); |
|
178 |
- } |
|
179 |
- |
|
180 |
- $this->message = $message; |
|
181 |
- |
|
182 |
- return $this; |
|
183 |
- } |
|
184 |
- |
|
185 |
- public function getCode() |
|
186 |
- { |
|
187 |
- return $this->code; |
|
188 |
- } |
|
189 |
- |
|
190 |
- /** |
|
191 |
- * @return $this |
|
192 |
- */ |
|
193 |
- public function setCode($code) |
|
194 |
- { |
|
195 |
- $this->code = $code; |
|
196 |
- |
|
197 |
- return $this; |
|
198 |
- } |
|
199 |
- |
|
200 |
- public function getPrevious() |
|
201 |
- { |
|
202 |
- return $this->previous; |
|
203 |
- } |
|
204 |
- |
|
205 |
- /** |
|
206 |
- * @return $this |
|
207 |
- */ |
|
208 |
- public function setPrevious(self $previous) |
|
209 |
- { |
|
210 |
- $this->previous = $previous; |
|
211 |
- |
|
212 |
- return $this; |
|
213 |
- } |
|
214 |
- |
|
215 |
- public function getAllPrevious() |
|
216 |
- { |
|
217 |
- $exceptions = []; |
|
218 |
- $e = $this; |
|
219 |
- while ($e = $e->getPrevious()) { |
|
220 |
- $exceptions[] = $e; |
|
221 |
- } |
|
222 |
- |
|
223 |
- return $exceptions; |
|
224 |
- } |
|
225 |
- |
|
226 |
- public function getTrace() |
|
227 |
- { |
|
228 |
- return $this->trace; |
|
229 |
- } |
|
230 |
- |
|
231 |
- /** |
|
232 |
- * @deprecated since 4.1, use {@see setTraceFromThrowable()} instead. |
|
233 |
- */ |
|
234 |
- public function setTraceFromException(\Exception $exception) |
|
235 |
- { |
|
236 |
- @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use "setTraceFromThrowable()" instead.', __METHOD__), E_USER_DEPRECATED); |
|
237 |
- |
|
238 |
- $this->setTraceFromThrowable($exception); |
|
239 |
- } |
|
240 |
- |
|
241 |
- public function setTraceFromThrowable(\Throwable $throwable) |
|
242 |
- { |
|
243 |
- $this->traceAsString = $throwable->getTraceAsString(); |
|
244 |
- |
|
245 |
- return $this->setTrace($throwable->getTrace(), $throwable->getFile(), $throwable->getLine()); |
|
246 |
- } |
|
247 |
- |
|
248 |
- /** |
|
249 |
- * @return $this |
|
250 |
- */ |
|
251 |
- public function setTrace($trace, $file, $line) |
|
252 |
- { |
|
253 |
- $this->trace = []; |
|
254 |
- $this->trace[] = [ |
|
255 |
- 'namespace' => '', |
|
256 |
- 'short_class' => '', |
|
257 |
- 'class' => '', |
|
258 |
- 'type' => '', |
|
259 |
- 'function' => '', |
|
260 |
- 'file' => $file, |
|
261 |
- 'line' => $line, |
|
262 |
- 'args' => [], |
|
263 |
- ]; |
|
264 |
- foreach ($trace as $entry) { |
|
265 |
- $class = ''; |
|
266 |
- $namespace = ''; |
|
267 |
- if (isset($entry['class'])) { |
|
268 |
- $parts = explode('\\', $entry['class']); |
|
269 |
- $class = array_pop($parts); |
|
270 |
- $namespace = implode('\\', $parts); |
|
271 |
- } |
|
272 |
- |
|
273 |
- $this->trace[] = [ |
|
274 |
- 'namespace' => $namespace, |
|
275 |
- 'short_class' => $class, |
|
276 |
- 'class' => isset($entry['class']) ? $entry['class'] : '', |
|
277 |
- 'type' => isset($entry['type']) ? $entry['type'] : '', |
|
278 |
- 'function' => isset($entry['function']) ? $entry['function'] : null, |
|
279 |
- 'file' => isset($entry['file']) ? $entry['file'] : null, |
|
280 |
- 'line' => isset($entry['line']) ? $entry['line'] : null, |
|
281 |
- 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : [], |
|
282 |
- ]; |
|
283 |
- } |
|
284 |
- |
|
285 |
- return $this; |
|
286 |
- } |
|
287 |
- |
|
288 |
- private function flattenArgs($args, $level = 0, &$count = 0) |
|
289 |
- { |
|
290 |
- $result = []; |
|
291 |
- foreach ($args as $key => $value) { |
|
292 |
- if (++$count > 1e4) { |
|
293 |
- return ['array', '*SKIPPED over 10000 entries*']; |
|
294 |
- } |
|
295 |
- if ($value instanceof \__PHP_Incomplete_Class) { |
|
296 |
- // is_object() returns false on PHP<=7.1 |
|
297 |
- $result[$key] = ['incomplete-object', $this->getClassNameFromIncomplete($value)]; |
|
298 |
- } elseif (\is_object($value)) { |
|
299 |
- $result[$key] = ['object', \get_class($value)]; |
|
300 |
- } elseif (\is_array($value)) { |
|
301 |
- if ($level > 10) { |
|
302 |
- $result[$key] = ['array', '*DEEP NESTED ARRAY*']; |
|
303 |
- } else { |
|
304 |
- $result[$key] = ['array', $this->flattenArgs($value, $level + 1, $count)]; |
|
305 |
- } |
|
306 |
- } elseif (null === $value) { |
|
307 |
- $result[$key] = ['null', null]; |
|
308 |
- } elseif (\is_bool($value)) { |
|
309 |
- $result[$key] = ['boolean', $value]; |
|
310 |
- } elseif (\is_int($value)) { |
|
311 |
- $result[$key] = ['integer', $value]; |
|
312 |
- } elseif (\is_float($value)) { |
|
313 |
- $result[$key] = ['float', $value]; |
|
314 |
- } elseif (\is_resource($value)) { |
|
315 |
- $result[$key] = ['resource', get_resource_type($value)]; |
|
316 |
- } else { |
|
317 |
- $result[$key] = ['string', (string) $value]; |
|
318 |
- } |
|
319 |
- } |
|
320 |
- |
|
321 |
- return $result; |
|
322 |
- } |
|
323 |
- |
|
324 |
- private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value) |
|
325 |
- { |
|
326 |
- $array = new \ArrayObject($value); |
|
327 |
- |
|
328 |
- return $array['__PHP_Incomplete_Class_Name']; |
|
329 |
- } |
|
330 |
- |
|
331 |
- public function getTraceAsString() |
|
332 |
- { |
|
333 |
- return $this->traceAsString; |
|
334 |
- } |
|
335 |
- |
|
336 |
- public function getAsString() |
|
337 |
- { |
|
338 |
- $message = ''; |
|
339 |
- $next = false; |
|
340 |
- |
|
341 |
- foreach (array_reverse(array_merge([$this], $this->getAllPrevious())) as $exception) { |
|
342 |
- if ($next) { |
|
343 |
- $message .= 'Next '; |
|
344 |
- } else { |
|
345 |
- $next = true; |
|
346 |
- } |
|
347 |
- $message .= $exception->getClass(); |
|
348 |
- |
|
349 |
- if ('' != $exception->getMessage()) { |
|
350 |
- $message .= ': '.$exception->getMessage(); |
|
351 |
- } |
|
352 |
- |
|
353 |
- $message .= ' in '.$exception->getFile().':'.$exception->getLine(). |
|
354 |
- "\nStack trace:\n".$exception->getTraceAsString()."\n\n"; |
|
355 |
- } |
|
356 |
- |
|
357 |
- return rtrim($message); |
|
358 |
- } |
|
359 |
-} |
1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,359 @@ |
1 |
+<?php |
|
2 |
+ |
|
3 |
+/* |
|
4 |
+ * This file is part of the Symfony package. |
|
5 |
+ * |
|
6 |
+ * (c) Fabien Potencier <fabien@symfony.com> |
|
7 |
+ * |
|
8 |
+ * For the full copyright and license information, please view the LICENSE |
|
9 |
+ * file that was distributed with this source code. |
|
10 |
+ */ |
|
11 |
+ |
|
12 |
+namespace Symfony\Component\Debug\Exception; |
|
13 |
+ |
|
14 |
+use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface; |
|
15 |
+use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; |
|
16 |
+ |
|
17 |
+/** |
|
18 |
+ * FlattenException wraps a PHP Error or Exception to be able to serialize it. |
|
19 |
+ * |
|
20 |
+ * Basically, this class removes all objects from the trace. |
|
21 |
+ * |
|
22 |
+ * @author Fabien Potencier <fabien@symfony.com> |
|
23 |
+ */ |
|
24 |
+class FlattenException |
|
25 |
+{ |
|
26 |
+ private $message; |
|
27 |
+ private $code; |
|
28 |
+ private $previous; |
|
29 |
+ private $trace; |
|
30 |
+ private $traceAsString; |
|
31 |
+ private $class; |
|
32 |
+ private $statusCode; |
|
33 |
+ private $headers; |
|
34 |
+ private $file; |
|
35 |
+ private $line; |
|
36 |
+ |
|
37 |
+ public static function create(\Exception $exception, $statusCode = null, array $headers = []) |
|
38 |
+ { |
|
39 |
+ return static::createFromThrowable($exception, $statusCode, $headers); |
|
40 |
+ } |
|
41 |
+ |
|
42 |
+ public static function createFromThrowable(\Throwable $exception, ?int $statusCode = null, array $headers = []): self |
|
43 |
+ { |
|
44 |
+ $e = new static(); |
|
45 |
+ $e->setMessage($exception->getMessage()); |
|
46 |
+ $e->setCode($exception->getCode()); |
|
47 |
+ |
|
48 |
+ if ($exception instanceof HttpExceptionInterface) { |
|
49 |
+ $statusCode = $exception->getStatusCode(); |
|
50 |
+ $headers = array_merge($headers, $exception->getHeaders()); |
|
51 |
+ } elseif ($exception instanceof RequestExceptionInterface) { |
|
52 |
+ $statusCode = 400; |
|
53 |
+ } |
|
54 |
+ |
|
55 |
+ if (null === $statusCode) { |
|
56 |
+ $statusCode = 500; |
|
57 |
+ } |
|
58 |
+ |
|
59 |
+ $e->setStatusCode($statusCode); |
|
60 |
+ $e->setHeaders($headers); |
|
61 |
+ $e->setTraceFromThrowable($exception); |
|
62 |
+ $e->setClass($exception instanceof FatalThrowableError ? $exception->getOriginalClassName() : \get_class($exception)); |
|
63 |
+ $e->setFile($exception->getFile()); |
|
64 |
+ $e->setLine($exception->getLine()); |
|
65 |
+ |
|
66 |
+ $previous = $exception->getPrevious(); |
|
67 |
+ |
|
68 |
+ if ($previous instanceof \Throwable) { |
|
69 |
+ $e->setPrevious(static::createFromThrowable($previous)); |
|
70 |
+ } |
|
71 |
+ |
|
72 |
+ return $e; |
|
73 |
+ } |
|
74 |
+ |
|
75 |
+ public function toArray() |
|
76 |
+ { |
|
77 |
+ $exceptions = []; |
|
78 |
+ foreach (array_merge([$this], $this->getAllPrevious()) as $exception) { |
|
79 |
+ $exceptions[] = [ |
|
80 |
+ 'message' => $exception->getMessage(), |
|
81 |
+ 'class' => $exception->getClass(), |
|
82 |
+ 'trace' => $exception->getTrace(), |
|
83 |
+ ]; |
|
84 |
+ } |
|
85 |
+ |
|
86 |
+ return $exceptions; |
|
87 |
+ } |
|
88 |
+ |
|
89 |
+ public function getStatusCode() |
|
90 |
+ { |
|
91 |
+ return $this->statusCode; |
|
92 |
+ } |
|
93 |
+ |
|
94 |
+ /** |
|
95 |
+ * @return $this |
|
96 |
+ */ |
|
97 |
+ public function setStatusCode($code) |
|
98 |
+ { |
|
99 |
+ $this->statusCode = $code; |
|
100 |
+ |
|
101 |
+ return $this; |
|
102 |
+ } |
|
103 |
+ |
|
104 |
+ public function getHeaders() |
|
105 |
+ { |
|
106 |
+ return $this->headers; |
|
107 |
+ } |
|
108 |
+ |
|
109 |
+ /** |
|
110 |
+ * @return $this |
|
111 |
+ */ |
|
112 |
+ public function setHeaders(array $headers) |
|
113 |
+ { |
|
114 |
+ $this->headers = $headers; |
|
115 |
+ |
|
116 |
+ return $this; |
|
117 |
+ } |
|
118 |
+ |
|
119 |
+ public function getClass() |
|
120 |
+ { |
|
121 |
+ return $this->class; |
|
122 |
+ } |
|
123 |
+ |
|
124 |
+ /** |
|
125 |
+ * @return $this |
|
126 |
+ */ |
|
127 |
+ public function setClass($class) |
|
128 |
+ { |
|
129 |
+ $this->class = 'c' === $class[0] && 0 === strpos($class, "class@anonymous\0") ? get_parent_class($class).'@anonymous' : $class; |
|
130 |
+ |
|
131 |
+ return $this; |
|
132 |
+ } |
|
133 |
+ |
|
134 |
+ public function getFile() |
|
135 |
+ { |
|
136 |
+ return $this->file; |
|
137 |
+ } |
|
138 |
+ |
|
139 |
+ /** |
|
140 |
+ * @return $this |
|
141 |
+ */ |
|
142 |
+ public function setFile($file) |
|
143 |
+ { |
|
144 |
+ $this->file = $file; |
|
145 |
+ |
|
146 |
+ return $this; |
|
147 |
+ } |
|
148 |
+ |
|
149 |
+ public function getLine() |
|
150 |
+ { |
|
151 |
+ return $this->line; |
|
152 |
+ } |
|
153 |
+ |
|
154 |
+ /** |
|
155 |
+ * @return $this |
|
156 |
+ */ |
|
157 |
+ public function setLine($line) |
|
158 |
+ { |
|
159 |
+ $this->line = $line; |
|
160 |
+ |
|
161 |
+ return $this; |
|
162 |
+ } |
|
163 |
+ |
|
164 |
+ public function getMessage() |
|
165 |
+ { |
|
166 |
+ return $this->message; |
|
167 |
+ } |
|
168 |
+ |
|
169 |
+ /** |
|
170 |
+ * @return $this |
|
171 |
+ */ |
|
172 |
+ public function setMessage($message) |
|
173 |
+ { |
|
174 |
+ if (false !== strpos($message, "class@anonymous\0")) { |
|
175 |
+ $message = preg_replace_callback('/class@anonymous\x00.*?\.php0x?[0-9a-fA-F]++/', function ($m) { |
|
176 |
+ return class_exists($m[0], false) ? get_parent_class($m[0]).'@anonymous' : $m[0]; |
|
177 |
+ }, $message); |
|
178 |
+ } |
|
179 |
+ |
|
180 |
+ $this->message = $message; |
|
181 |
+ |
|
182 |
+ return $this; |
|
183 |
+ } |
|
184 |
+ |
|
185 |
+ public function getCode() |
|
186 |
+ { |
|
187 |
+ return $this->code; |
|
188 |
+ } |
|
189 |
+ |
|
190 |
+ /** |
|
191 |
+ * @return $this |
|
192 |
+ */ |
|
193 |
+ public function setCode($code) |
|
194 |
+ { |
|
195 |
+ $this->code = $code; |
|
196 |
+ |
|
197 |
+ return $this; |
|
198 |
+ } |
|
199 |
+ |
|
200 |
+ public function getPrevious() |
|
201 |
+ { |
|
202 |
+ return $this->previous; |
|
203 |
+ } |
|
204 |
+ |
|
205 |
+ /** |
|
206 |
+ * @return $this |
|
207 |
+ */ |
|
208 |
+ public function setPrevious(self $previous) |
|
209 |
+ { |
|
210 |
+ $this->previous = $previous; |
|
211 |
+ |
|
212 |
+ return $this; |
|
213 |
+ } |
|
214 |
+ |
|
215 |
+ public function getAllPrevious() |
|
216 |
+ { |
|
217 |
+ $exceptions = []; |
|
218 |
+ $e = $this; |
|
219 |
+ while ($e = $e->getPrevious()) { |
|
220 |
+ $exceptions[] = $e; |
|
221 |
+ } |
|
222 |
+ |
|
223 |
+ return $exceptions; |
|
224 |
+ } |
|
225 |
+ |
|
226 |
+ public function getTrace() |
|
227 |
+ { |
|
228 |
+ return $this->trace; |
|
229 |
+ } |
|
230 |
+ |
|
231 |
+ /** |
|
232 |
+ * @deprecated since 4.1, use {@see setTraceFromThrowable()} instead. |
|
233 |
+ */ |
|
234 |
+ public function setTraceFromException(\Exception $exception) |
|
235 |
+ { |
|
236 |
+ @trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1, use "setTraceFromThrowable()" instead.', __METHOD__), E_USER_DEPRECATED); |
|
237 |
+ |
|
238 |
+ $this->setTraceFromThrowable($exception); |
|
239 |
+ } |
|
240 |
+ |
|
241 |
+ public function setTraceFromThrowable(\Throwable $throwable) |
|
242 |
+ { |
|
243 |
+ $this->traceAsString = $throwable->getTraceAsString(); |
|
244 |
+ |
|
245 |
+ return $this->setTrace($throwable->getTrace(), $throwable->getFile(), $throwable->getLine()); |
|
246 |
+ } |
|
247 |
+ |
|
248 |
+ /** |
|
249 |
+ * @return $this |
|
250 |
+ */ |
|
251 |
+ public function setTrace($trace, $file, $line) |
|
252 |
+ { |
|
253 |
+ $this->trace = []; |
|
254 |
+ $this->trace[] = [ |
|
255 |
+ 'namespace' => '', |
|
256 |
+ 'short_class' => '', |
|
257 |
+ 'class' => '', |
|
258 |
+ 'type' => '', |
|
259 |
+ 'function' => '', |
|
260 |
+ 'file' => $file, |
|
261 |
+ 'line' => $line, |
|
262 |
+ 'args' => [], |
|
263 |
+ ]; |
|
264 |
+ foreach ($trace as $entry) { |
|
265 |
+ $class = ''; |
|
266 |
+ $namespace = ''; |
|
267 |
+ if (isset($entry['class'])) { |
|
268 |
+ $parts = explode('\\', $entry['class']); |
|
269 |
+ $class = array_pop($parts); |
|
270 |
+ $namespace = implode('\\', $parts); |
|
271 |
+ } |
|
272 |
+ |
|
273 |
+ $this->trace[] = [ |
|
274 |
+ 'namespace' => $namespace, |
|
275 |
+ 'short_class' => $class, |
|
276 |
+ 'class' => isset($entry['class']) ? $entry['class'] : '', |
|
277 |
+ 'type' => isset($entry['type']) ? $entry['type'] : '', |
|
278 |
+ 'function' => isset($entry['function']) ? $entry['function'] : null, |
|
279 |
+ 'file' => isset($entry['file']) ? $entry['file'] : null, |
|
280 |
+ 'line' => isset($entry['line']) ? $entry['line'] : null, |
|
281 |
+ 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : [], |
|
282 |
+ ]; |
|
283 |
+ } |
|
284 |
+ |
|
285 |
+ return $this; |
|
286 |
+ } |
|
287 |
+ |
|
288 |
+ private function flattenArgs($args, $level = 0, &$count = 0) |
|
289 |
+ { |
|
290 |
+ $result = []; |
|
291 |
+ foreach ($args as $key => $value) { |
|
292 |
+ if (++$count > 1e4) { |
|
293 |
+ return ['array', '*SKIPPED over 10000 entries*']; |
|
294 |
+ } |
|
295 |
+ if ($value instanceof \__PHP_Incomplete_Class) { |
|
296 |
+ // is_object() returns false on PHP<=7.1 |
|
297 |
+ $result[$key] = ['incomplete-object', $this->getClassNameFromIncomplete($value)]; |
|
298 |
+ } elseif (\is_object($value)) { |
|
299 |
+ $result[$key] = ['object', \get_class($value)]; |
|
300 |
+ } elseif (\is_array($value)) { |
|
301 |
+ if ($level > 10) { |
|
302 |
+ $result[$key] = ['array', '*DEEP NESTED ARRAY*']; |
|
303 |
+ } else { |
|
304 |
+ $result[$key] = ['array', $this->flattenArgs($value, $level + 1, $count)]; |
|
305 |
+ } |
|
306 |
+ } elseif (null === $value) { |
|
307 |
+ $result[$key] = ['null', null]; |
|
308 |
+ } elseif (\is_bool($value)) { |
|
309 |
+ $result[$key] = ['boolean', $value]; |
|
310 |
+ } elseif (\is_int($value)) { |
|
311 |
+ $result[$key] = ['integer', $value]; |
|
312 |
+ } elseif (\is_float($value)) { |
|
313 |
+ $result[$key] = ['float', $value]; |
|
314 |
+ } elseif (\is_resource($value)) { |
|
315 |
+ $result[$key] = ['resource', get_resource_type($value)]; |
|
316 |
+ } else { |
|
317 |
+ $result[$key] = ['string', (string) $value]; |
|
318 |
+ } |
|
319 |
+ } |
|
320 |
+ |
|
321 |
+ return $result; |
|
322 |
+ } |
|
323 |
+ |
|
324 |
+ private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value) |
|
325 |
+ { |
|
326 |
+ $array = new \ArrayObject($value); |
|
327 |
+ |
|
328 |
+ return $array['__PHP_Incomplete_Class_Name']; |
|
329 |
+ } |
|
330 |
+ |
|
331 |
+ public function getTraceAsString() |
|
332 |
+ { |
|
333 |
+ return $this->traceAsString; |
|
334 |
+ } |
|
335 |
+ |
|
336 |
+ public function getAsString() |
|
337 |
+ { |
|
338 |
+ $message = ''; |
|
339 |
+ $next = false; |
|
340 |
+ |
|
341 |
+ foreach (array_reverse(array_merge([$this], $this->getAllPrevious())) as $exception) { |
|
342 |
+ if ($next) { |
|
343 |
+ $message .= 'Next '; |
|
344 |
+ } else { |
|
345 |
+ $next = true; |
|
346 |
+ } |
|
347 |
+ $message .= $exception->getClass(); |
|
348 |
+ |
|
349 |
+ if ('' != $exception->getMessage()) { |
|
350 |
+ $message .= ': '.$exception->getMessage(); |
|
351 |
+ } |
|
352 |
+ |
|
353 |
+ $message .= ' in '.$exception->getFile().':'.$exception->getLine(). |
|
354 |
+ "\nStack trace:\n".$exception->getTraceAsString()."\n\n"; |
|
355 |
+ } |
|
356 |
+ |
|
357 |
+ return rtrim($message); |
|
358 |
+ } |
|
359 |
+} |