Mercurial > hg > cmmr2012-drupal-site
comparison vendor/psy/psysh/src/Command/TraceCommand.php @ 4:a9cd425dd02b
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:11:55 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
3:307d7a7fd348 | 4:a9cd425dd02b |
---|---|
88 * | 88 * |
89 * @return array Formatted stacktrace lines | 89 * @return array Formatted stacktrace lines |
90 */ | 90 */ |
91 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true) | 91 protected function getBacktrace(\Exception $e, $count = null, $includePsy = true) |
92 { | 92 { |
93 if ($cwd = getcwd()) { | 93 if ($cwd = \getcwd()) { |
94 $cwd = rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; | 94 $cwd = \rtrim($cwd, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR; |
95 } | 95 } |
96 | 96 |
97 if ($count === null) { | 97 if ($count === null) { |
98 $count = PHP_INT_MAX; | 98 $count = PHP_INT_MAX; |
99 } | 99 } |
100 | 100 |
101 $lines = []; | 101 $lines = []; |
102 | 102 |
103 $trace = $e->getTrace(); | 103 $trace = $e->getTrace(); |
104 array_unshift($trace, [ | 104 \array_unshift($trace, [ |
105 'function' => '', | 105 'function' => '', |
106 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', | 106 'file' => $e->getFile() !== null ? $e->getFile() : 'n/a', |
107 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', | 107 'line' => $e->getLine() !== null ? $e->getLine() : 'n/a', |
108 'args' => [], | 108 'args' => [], |
109 ]); | 109 ]); |
110 | 110 |
111 if (!$includePsy) { | 111 if (!$includePsy) { |
112 for ($i = count($trace) - 1; $i >= 0; $i--) { | 112 for ($i = \count($trace) - 1; $i >= 0; $i--) { |
113 $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function']; | 113 $thing = isset($trace[$i]['class']) ? $trace[$i]['class'] : $trace[$i]['function']; |
114 if (preg_match('/\\\\?Psy\\\\/', $thing)) { | 114 if (\preg_match('/\\\\?Psy\\\\/', $thing)) { |
115 $trace = array_slice($trace, $i + 1); | 115 $trace = \array_slice($trace, $i + 1); |
116 break; | 116 break; |
117 } | 117 } |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 for ($i = 0, $count = min($count, count($trace)); $i < $count; $i++) { | 121 for ($i = 0, $count = \min($count, \count($trace)); $i < $count; $i++) { |
122 $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; | 122 $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : ''; |
123 $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; | 123 $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : ''; |
124 $function = $trace[$i]['function']; | 124 $function = $trace[$i]['function']; |
125 $file = isset($trace[$i]['file']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a'; | 125 $file = isset($trace[$i]['file']) ? $this->replaceCwd($cwd, $trace[$i]['file']) : 'n/a'; |
126 $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a'; | 126 $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a'; |
127 | 127 |
128 // Leave execution loop out of the `eval()'d code` lines | 128 // Leave execution loop out of the `eval()'d code` lines |
129 if (preg_match("#/src/Execution(?:Loop)?Closure.php\(\d+\) : eval\(\)'d code$#", str_replace('\\', '/', $file))) { | 129 if (\preg_match("#/src/Execution(?:Loop)?Closure.php\(\d+\) : eval\(\)'d code$#", \str_replace('\\', '/', $file))) { |
130 $file = "eval()'d code"; | 130 $file = "eval()'d code"; |
131 } | 131 } |
132 | 132 |
133 // Skip any lines that don't match our filter options | 133 // Skip any lines that don't match our filter options |
134 if (!$this->filter->match(sprintf('%s%s%s() at %s:%s', $class, $type, $function, $file, $line))) { | 134 if (!$this->filter->match(\sprintf('%s%s%s() at %s:%s', $class, $type, $function, $file, $line))) { |
135 continue; | 135 continue; |
136 } | 136 } |
137 | 137 |
138 $lines[] = sprintf( | 138 $lines[] = \sprintf( |
139 ' <class>%s</class>%s%s() at <info>%s:%s</info>', | 139 ' <class>%s</class>%s%s() at <info>%s:%s</info>', |
140 OutputFormatter::escape($class), | 140 OutputFormatter::escape($class), |
141 OutputFormatter::escape($type), | 141 OutputFormatter::escape($type), |
142 OutputFormatter::escape($function), | 142 OutputFormatter::escape($function), |
143 OutputFormatter::escape($file), | 143 OutputFormatter::escape($file), |
159 private function replaceCwd($cwd, $file) | 159 private function replaceCwd($cwd, $file) |
160 { | 160 { |
161 if ($cwd === false) { | 161 if ($cwd === false) { |
162 return $file; | 162 return $file; |
163 } else { | 163 } else { |
164 return preg_replace('/^' . preg_quote($cwd, '/') . '/', '', $file); | 164 return \preg_replace('/^' . \preg_quote($cwd, '/') . '/', '', $file); |
165 } | 165 } |
166 } | 166 } |
167 } | 167 } |