Mercurial > hg > isophonics-drupal-site
comparison vendor/symfony/debug/Exception/FlattenException.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | c2387f117808 |
children |
comparison
equal
deleted
inserted
replaced
16:c2387f117808 | 17:129ea1e6d783 |
---|---|
31 private $statusCode; | 31 private $statusCode; |
32 private $headers; | 32 private $headers; |
33 private $file; | 33 private $file; |
34 private $line; | 34 private $line; |
35 | 35 |
36 public static function create(\Exception $exception, $statusCode = null, array $headers = array()) | 36 public static function create(\Exception $exception, $statusCode = null, array $headers = []) |
37 { | 37 { |
38 $e = new static(); | 38 $e = new static(); |
39 $e->setMessage($exception->getMessage()); | 39 $e->setMessage($exception->getMessage()); |
40 $e->setCode($exception->getCode()); | 40 $e->setCode($exception->getCode()); |
41 | 41 |
51 } | 51 } |
52 | 52 |
53 $e->setStatusCode($statusCode); | 53 $e->setStatusCode($statusCode); |
54 $e->setHeaders($headers); | 54 $e->setHeaders($headers); |
55 $e->setTraceFromException($exception); | 55 $e->setTraceFromException($exception); |
56 $e->setClass(get_class($exception)); | 56 $e->setClass(\get_class($exception)); |
57 $e->setFile($exception->getFile()); | 57 $e->setFile($exception->getFile()); |
58 $e->setLine($exception->getLine()); | 58 $e->setLine($exception->getLine()); |
59 | 59 |
60 $previous = $exception->getPrevious(); | 60 $previous = $exception->getPrevious(); |
61 | 61 |
68 return $e; | 68 return $e; |
69 } | 69 } |
70 | 70 |
71 public function toArray() | 71 public function toArray() |
72 { | 72 { |
73 $exceptions = array(); | 73 $exceptions = []; |
74 foreach (array_merge(array($this), $this->getAllPrevious()) as $exception) { | 74 foreach (array_merge([$this], $this->getAllPrevious()) as $exception) { |
75 $exceptions[] = array( | 75 $exceptions[] = [ |
76 'message' => $exception->getMessage(), | 76 'message' => $exception->getMessage(), |
77 'class' => $exception->getClass(), | 77 'class' => $exception->getClass(), |
78 'trace' => $exception->getTrace(), | 78 'trace' => $exception->getTrace(), |
79 ); | 79 ]; |
80 } | 80 } |
81 | 81 |
82 return $exceptions; | 82 return $exceptions; |
83 } | 83 } |
84 | 84 |
162 $this->previous = $previous; | 162 $this->previous = $previous; |
163 } | 163 } |
164 | 164 |
165 public function getAllPrevious() | 165 public function getAllPrevious() |
166 { | 166 { |
167 $exceptions = array(); | 167 $exceptions = []; |
168 $e = $this; | 168 $e = $this; |
169 while ($e = $e->getPrevious()) { | 169 while ($e = $e->getPrevious()) { |
170 $exceptions[] = $e; | 170 $exceptions[] = $e; |
171 } | 171 } |
172 | 172 |
183 $this->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); | 183 $this->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine()); |
184 } | 184 } |
185 | 185 |
186 public function setTrace($trace, $file, $line) | 186 public function setTrace($trace, $file, $line) |
187 { | 187 { |
188 $this->trace = array(); | 188 $this->trace = []; |
189 $this->trace[] = array( | 189 $this->trace[] = [ |
190 'namespace' => '', | 190 'namespace' => '', |
191 'short_class' => '', | 191 'short_class' => '', |
192 'class' => '', | 192 'class' => '', |
193 'type' => '', | 193 'type' => '', |
194 'function' => '', | 194 'function' => '', |
195 'file' => $file, | 195 'file' => $file, |
196 'line' => $line, | 196 'line' => $line, |
197 'args' => array(), | 197 'args' => [], |
198 ); | 198 ]; |
199 foreach ($trace as $entry) { | 199 foreach ($trace as $entry) { |
200 $class = ''; | 200 $class = ''; |
201 $namespace = ''; | 201 $namespace = ''; |
202 if (isset($entry['class'])) { | 202 if (isset($entry['class'])) { |
203 $parts = explode('\\', $entry['class']); | 203 $parts = explode('\\', $entry['class']); |
204 $class = array_pop($parts); | 204 $class = array_pop($parts); |
205 $namespace = implode('\\', $parts); | 205 $namespace = implode('\\', $parts); |
206 } | 206 } |
207 | 207 |
208 $this->trace[] = array( | 208 $this->trace[] = [ |
209 'namespace' => $namespace, | 209 'namespace' => $namespace, |
210 'short_class' => $class, | 210 'short_class' => $class, |
211 'class' => isset($entry['class']) ? $entry['class'] : '', | 211 'class' => isset($entry['class']) ? $entry['class'] : '', |
212 'type' => isset($entry['type']) ? $entry['type'] : '', | 212 'type' => isset($entry['type']) ? $entry['type'] : '', |
213 'function' => isset($entry['function']) ? $entry['function'] : null, | 213 'function' => isset($entry['function']) ? $entry['function'] : null, |
214 'file' => isset($entry['file']) ? $entry['file'] : null, | 214 'file' => isset($entry['file']) ? $entry['file'] : null, |
215 'line' => isset($entry['line']) ? $entry['line'] : null, | 215 'line' => isset($entry['line']) ? $entry['line'] : null, |
216 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(), | 216 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : [], |
217 ); | 217 ]; |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 private function flattenArgs($args, $level = 0, &$count = 0) | 221 private function flattenArgs($args, $level = 0, &$count = 0) |
222 { | 222 { |
223 $result = array(); | 223 $result = []; |
224 foreach ($args as $key => $value) { | 224 foreach ($args as $key => $value) { |
225 if (++$count > 1e4) { | 225 if (++$count > 1e4) { |
226 return array('array', '*SKIPPED over 10000 entries*'); | 226 return ['array', '*SKIPPED over 10000 entries*']; |
227 } | 227 } |
228 if ($value instanceof \__PHP_Incomplete_Class) { | 228 if ($value instanceof \__PHP_Incomplete_Class) { |
229 // is_object() returns false on PHP<=7.1 | 229 // is_object() returns false on PHP<=7.1 |
230 $result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value)); | 230 $result[$key] = ['incomplete-object', $this->getClassNameFromIncomplete($value)]; |
231 } elseif (is_object($value)) { | 231 } elseif (\is_object($value)) { |
232 $result[$key] = array('object', get_class($value)); | 232 $result[$key] = ['object', \get_class($value)]; |
233 } elseif (is_array($value)) { | 233 } elseif (\is_array($value)) { |
234 if ($level > 10) { | 234 if ($level > 10) { |
235 $result[$key] = array('array', '*DEEP NESTED ARRAY*'); | 235 $result[$key] = ['array', '*DEEP NESTED ARRAY*']; |
236 } else { | 236 } else { |
237 $result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count)); | 237 $result[$key] = ['array', $this->flattenArgs($value, $level + 1, $count)]; |
238 } | 238 } |
239 } elseif (null === $value) { | 239 } elseif (null === $value) { |
240 $result[$key] = array('null', null); | 240 $result[$key] = ['null', null]; |
241 } elseif (is_bool($value)) { | 241 } elseif (\is_bool($value)) { |
242 $result[$key] = array('boolean', $value); | 242 $result[$key] = ['boolean', $value]; |
243 } elseif (is_int($value)) { | 243 } elseif (\is_int($value)) { |
244 $result[$key] = array('integer', $value); | 244 $result[$key] = ['integer', $value]; |
245 } elseif (is_float($value)) { | 245 } elseif (\is_float($value)) { |
246 $result[$key] = array('float', $value); | 246 $result[$key] = ['float', $value]; |
247 } elseif (is_resource($value)) { | 247 } elseif (\is_resource($value)) { |
248 $result[$key] = array('resource', get_resource_type($value)); | 248 $result[$key] = ['resource', get_resource_type($value)]; |
249 } else { | 249 } else { |
250 $result[$key] = array('string', (string) $value); | 250 $result[$key] = ['string', (string) $value]; |
251 } | 251 } |
252 } | 252 } |
253 | 253 |
254 return $result; | 254 return $result; |
255 } | 255 } |