@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | */ |
| 153 | 153 | protected function call() |
| 154 | 154 | { |
| 155 | - return function ($stack, $pipe) { |
|
| 156 | - return function ($passable) use ($stack, $pipe) { |
|
| 155 | + return function($stack, $pipe) { |
|
| 156 | + return function($passable) use ($stack, $pipe) { |
|
| 157 | 157 | try |
| 158 | 158 | { |
| 159 | 159 | if (is_callable($pipe)) |
@@ -215,12 +215,12 @@ discard block |
||
| 215 | 215 | */ |
| 216 | 216 | protected function prepareDestination(Closure $destination) |
| 217 | 217 | { |
| 218 | - return function ($passable) use ($destination) { |
|
| 218 | + return function($passable) use ($destination) { |
|
| 219 | 219 | try |
| 220 | 220 | { |
| 221 | 221 | return $destination($passable); |
| 222 | 222 | } |
| 223 | - catch(Throwable $e) |
|
| 223 | + catch (Throwable $e) |
|
| 224 | 224 | { |
| 225 | 225 | return $this->handleException($passable, $e); |
| 226 | 226 | } |
@@ -159,16 +159,14 @@ discard block |
||
| 159 | 159 | if (is_callable($pipe)) |
| 160 | 160 | { |
| 161 | 161 | return $pipe($passable, $stack); |
| 162 | - } |
|
| 163 | - elseif ( ! is_object($pipe)) |
|
| 162 | + } elseif ( ! is_object($pipe)) |
|
| 164 | 163 | { |
| 165 | 164 | [$name, $parameters] = $this->parsePipeString($pipe); |
| 166 | 165 | |
| 167 | 166 | $pipe = $this->getContainer()->make($name); |
| 168 | 167 | |
| 169 | 168 | $parameters = array_merge([$passable, $stack], $parameters); |
| 170 | - } |
|
| 171 | - else |
|
| 169 | + } else |
|
| 172 | 170 | { |
| 173 | 171 | $parameters = [$passable, $stack]; |
| 174 | 172 | } |
@@ -178,8 +176,7 @@ discard block |
||
| 178 | 176 | : $pipe(...$parameters); |
| 179 | 177 | |
| 180 | 178 | return $pipeline; |
| 181 | - } |
|
| 182 | - catch (Throwable $e) |
|
| 179 | + } catch (Throwable $e) |
|
| 183 | 180 | { |
| 184 | 181 | return $this->handleException($passable, $e); |
| 185 | 182 | } |
@@ -219,8 +216,7 @@ discard block |
||
| 219 | 216 | try |
| 220 | 217 | { |
| 221 | 218 | return $destination($passable); |
| 222 | - } |
|
| 223 | - catch(Throwable $e) |
|
| 219 | + } catch(Throwable $e) |
|
| 224 | 220 | { |
| 225 | 221 | return $this->handleException($passable, $e); |
| 226 | 222 | } |
@@ -150,7 +150,7 @@ |
||
| 150 | 150 | |
| 151 | 151 | if ($seconds <= 0) |
| 152 | 152 | { |
| 153 | - return ' ms'; |
|
| 153 | + return ' ms'; |
|
| 154 | 154 | } |
| 155 | 155 | elseif ($seconds > 0) |
| 156 | 156 | { |
@@ -151,8 +151,7 @@ |
||
| 151 | 151 | if ($seconds <= 0) |
| 152 | 152 | { |
| 153 | 153 | return ' ms'; |
| 154 | - } |
|
| 155 | - elseif ($seconds > 0) |
|
| 154 | + } elseif ($seconds > 0) |
|
| 156 | 155 | { |
| 157 | 156 | return ' s'; |
| 158 | 157 | } |
@@ -42,450 +42,450 @@ |
||
| 42 | 42 | */ |
| 43 | 43 | class PleasingPageHandler extends MainHandler |
| 44 | 44 | { |
| 45 | - /** |
|
| 46 | - * The brand main of handler. |
|
| 47 | - * |
|
| 48 | - * @var string $brand |
|
| 49 | - */ |
|
| 50 | - protected $brand = 'Lenevor Debug'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * A string identifier for a known IDE/text editor, or a closure |
|
| 54 | - * that resolves a string that can be used to open a given file |
|
| 55 | - * in an editor. |
|
| 56 | - * |
|
| 57 | - * @var mixed $editor |
|
| 58 | - */ |
|
| 59 | - protected $editor; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * A list of known editor strings. |
|
| 63 | - * |
|
| 64 | - * @var array $editors |
|
| 65 | - */ |
|
| 66 | - protected $editors = [ |
|
| 67 | - "vscode" => "vscode://file/%file:%line", |
|
| 68 | - "sublime" => "subl://open?url=file://%file&line=%line", |
|
| 69 | - "phpstorm" => "phpstorm://open?file://%file&line=%line", |
|
| 70 | - "textmate" => "txmt://open?url=file://%file&line=%line", |
|
| 71 | - "atom" => "atom://core/open/file?filename=%file&line=%line", |
|
| 72 | - ]; |
|
| 45 | + /** |
|
| 46 | + * The brand main of handler. |
|
| 47 | + * |
|
| 48 | + * @var string $brand |
|
| 49 | + */ |
|
| 50 | + protected $brand = 'Lenevor Debug'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * A string identifier for a known IDE/text editor, or a closure |
|
| 54 | + * that resolves a string that can be used to open a given file |
|
| 55 | + * in an editor. |
|
| 56 | + * |
|
| 57 | + * @var mixed $editor |
|
| 58 | + */ |
|
| 59 | + protected $editor; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * A list of known editor strings. |
|
| 63 | + * |
|
| 64 | + * @var array $editors |
|
| 65 | + */ |
|
| 66 | + protected $editors = [ |
|
| 67 | + "vscode" => "vscode://file/%file:%line", |
|
| 68 | + "sublime" => "subl://open?url=file://%file&line=%line", |
|
| 69 | + "phpstorm" => "phpstorm://open?file://%file&line=%line", |
|
| 70 | + "textmate" => "txmt://open?url=file://%file&line=%line", |
|
| 71 | + "atom" => "atom://core/open/file?filename=%file&line=%line", |
|
| 72 | + ]; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * The page title main of handler. |
|
| 76 | - * |
|
| 77 | - * @var string $pageTitle |
|
| 78 | - */ |
|
| 79 | - protected $pageTitle = 'Lenevor Debug! There was an error.'; |
|
| 74 | + /** |
|
| 75 | + * The page title main of handler. |
|
| 76 | + * |
|
| 77 | + * @var string $pageTitle |
|
| 78 | + */ |
|
| 79 | + protected $pageTitle = 'Lenevor Debug! There was an error.'; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Fast lookup cache for known resource locations. |
|
| 83 | - * |
|
| 84 | - * @var array $resourceCache |
|
| 85 | - */ |
|
| 86 | - protected $resourceCache = []; |
|
| 81 | + /** |
|
| 82 | + * Fast lookup cache for known resource locations. |
|
| 83 | + * |
|
| 84 | + * @var array $resourceCache |
|
| 85 | + */ |
|
| 86 | + protected $resourceCache = []; |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The path to the directory containing the html error template directories. |
|
| 90 | - * |
|
| 91 | - * @var array $searchPaths |
|
| 92 | - */ |
|
| 93 | - protected $searchPaths = []; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Gets the table of data. |
|
| 97 | - * |
|
| 98 | - * @var array $tables |
|
| 99 | - */ |
|
| 100 | - protected $tables = []; |
|
| 88 | + /** |
|
| 89 | + * The path to the directory containing the html error template directories. |
|
| 90 | + * |
|
| 91 | + * @var array $searchPaths |
|
| 92 | + */ |
|
| 93 | + protected $searchPaths = []; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Gets the table of data. |
|
| 97 | + * |
|
| 98 | + * @var array $tables |
|
| 99 | + */ |
|
| 100 | + protected $tables = []; |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * The template handler system. |
|
| 104 | - * |
|
| 105 | - * @var string $template |
|
| 106 | - */ |
|
| 107 | - protected $template; |
|
| 102 | + /** |
|
| 103 | + * The template handler system. |
|
| 104 | + * |
|
| 105 | + * @var string $template |
|
| 106 | + */ |
|
| 107 | + protected $template; |
|
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Constructor. The PleasingPageHandler class. |
|
| 111 | - * |
|
| 112 | - * @return void |
|
| 113 | - */ |
|
| 114 | - public function __construct() |
|
| 115 | - { |
|
| 116 | - $this->template = new TemplateHandler; |
|
| 117 | - $this->searchPaths[] = dirname(__DIR__).DIRECTORY_SEPARATOR.'Resources'; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Adds an editor resolver, identified by a string name, and that may be a |
|
| 122 | - * string path, or a callable resolver. |
|
| 123 | - * |
|
| 124 | - * @param string $identifier |
|
| 125 | - * @param string|\Callable $resolver |
|
| 126 | - * |
|
| 127 | - * @return void |
|
| 128 | - */ |
|
| 129 | - public function addEditor($identifier, $resolver) |
|
| 130 | - { |
|
| 131 | - $this->editors[$identifier] = $resolver; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Adds an entry to the list of tables displayed in the template. |
|
| 136 | - * The expected data is a simple associative array. Any nested arrays |
|
| 137 | - * will be flattened with print_r. |
|
| 138 | - * |
|
| 139 | - * @param \Syscodes\Contracts\Debug\Table $table |
|
| 140 | - * |
|
| 141 | - * @return array |
|
| 142 | - */ |
|
| 143 | - public function addTables(Table $table) |
|
| 144 | - { |
|
| 145 | - $this->tables[] = $table; |
|
| 146 | - } |
|
| 109 | + /** |
|
| 110 | + * Constructor. The PleasingPageHandler class. |
|
| 111 | + * |
|
| 112 | + * @return void |
|
| 113 | + */ |
|
| 114 | + public function __construct() |
|
| 115 | + { |
|
| 116 | + $this->template = new TemplateHandler; |
|
| 117 | + $this->searchPaths[] = dirname(__DIR__).DIRECTORY_SEPARATOR.'Resources'; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Adds an editor resolver, identified by a string name, and that may be a |
|
| 122 | + * string path, or a callable resolver. |
|
| 123 | + * |
|
| 124 | + * @param string $identifier |
|
| 125 | + * @param string|\Callable $resolver |
|
| 126 | + * |
|
| 127 | + * @return void |
|
| 128 | + */ |
|
| 129 | + public function addEditor($identifier, $resolver) |
|
| 130 | + { |
|
| 131 | + $this->editors[$identifier] = $resolver; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Adds an entry to the list of tables displayed in the template. |
|
| 136 | + * The expected data is a simple associative array. Any nested arrays |
|
| 137 | + * will be flattened with print_r. |
|
| 138 | + * |
|
| 139 | + * @param \Syscodes\Contracts\Debug\Table $table |
|
| 140 | + * |
|
| 141 | + * @return array |
|
| 142 | + */ |
|
| 143 | + public function addTables(Table $table) |
|
| 144 | + { |
|
| 145 | + $this->tables[] = $table; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Gathers the variables that will be made available to the view. |
|
| 150 | - * |
|
| 151 | - * @return array |
|
| 152 | - */ |
|
| 153 | - protected function collectionVars() |
|
| 154 | - { |
|
| 155 | - $supervisor = $this->getSupervisor(); |
|
| 156 | - $style = file_get_contents($this->getResource('css/debug.base.css')); |
|
| 157 | - $jscript = file_get_contents($this->getResource('js/debug.base.js')); |
|
| 158 | - $tables = array_merge($this->getDefaultTables(), $this->tables); |
|
| 148 | + /** |
|
| 149 | + * Gathers the variables that will be made available to the view. |
|
| 150 | + * |
|
| 151 | + * @return array |
|
| 152 | + */ |
|
| 153 | + protected function collectionVars() |
|
| 154 | + { |
|
| 155 | + $supervisor = $this->getSupervisor(); |
|
| 156 | + $style = file_get_contents($this->getResource('css/debug.base.css')); |
|
| 157 | + $jscript = file_get_contents($this->getResource('js/debug.base.js')); |
|
| 158 | + $tables = array_merge($this->getDefaultTables(), $this->tables); |
|
| 159 | 159 | |
| 160 | - return [ |
|
| 161 | - 'class' => explode('\\', $supervisor->getExceptionName()), |
|
| 162 | - 'stylesheet' => preg_replace('#[\r\n\t ]+#', ' ', $style), |
|
| 163 | - 'javascript' => preg_replace('#[\r\n\t ]+#', ' ', $jscript), |
|
| 164 | - 'header' => $this->getResource('views/header.php'), |
|
| 165 | - 'sidebar' => $this->getResource('views/sidebar.php'), |
|
| 166 | - 'frame_description' => $this->getResource('views/frame_description.php'), |
|
| 167 | - 'frame_list' => $this->getResource('views/frame_list.php'), |
|
| 168 | - 'details_panel' => $this->getResource('views/details_panel.php'), |
|
| 169 | - 'code_source' => $this->getResource('views/code_source.php'), |
|
| 170 | - 'details_content' => $this->getResource('views/details_content.php'), |
|
| 171 | - 'footer' => $this->getResource('views/footer.php'), |
|
| 172 | - 'plain_exception' => Formatter::formatExceptionAsPlainText($this->getSupervisor()), |
|
| 173 | - 'handler' => $this, |
|
| 174 | - 'handlers' => $this->getDebug()->getHandlers(), |
|
| 175 | - 'debug' => $this->getDebug(), |
|
| 176 | - 'code' => $this->getExceptionCode(), |
|
| 177 | - 'message' => $supervisor->getExceptionMessage(), |
|
| 178 | - 'frames' => $this->getExceptionFrames(), |
|
| 179 | - 'tables' => $this->getProcessTables($tables), |
|
| 180 | - ]; |
|
| 181 | - } |
|
| 160 | + return [ |
|
| 161 | + 'class' => explode('\\', $supervisor->getExceptionName()), |
|
| 162 | + 'stylesheet' => preg_replace('#[\r\n\t ]+#', ' ', $style), |
|
| 163 | + 'javascript' => preg_replace('#[\r\n\t ]+#', ' ', $jscript), |
|
| 164 | + 'header' => $this->getResource('views/header.php'), |
|
| 165 | + 'sidebar' => $this->getResource('views/sidebar.php'), |
|
| 166 | + 'frame_description' => $this->getResource('views/frame_description.php'), |
|
| 167 | + 'frame_list' => $this->getResource('views/frame_list.php'), |
|
| 168 | + 'details_panel' => $this->getResource('views/details_panel.php'), |
|
| 169 | + 'code_source' => $this->getResource('views/code_source.php'), |
|
| 170 | + 'details_content' => $this->getResource('views/details_content.php'), |
|
| 171 | + 'footer' => $this->getResource('views/footer.php'), |
|
| 172 | + 'plain_exception' => Formatter::formatExceptionAsPlainText($this->getSupervisor()), |
|
| 173 | + 'handler' => $this, |
|
| 174 | + 'handlers' => $this->getDebug()->getHandlers(), |
|
| 175 | + 'debug' => $this->getDebug(), |
|
| 176 | + 'code' => $this->getExceptionCode(), |
|
| 177 | + 'message' => $supervisor->getExceptionMessage(), |
|
| 178 | + 'frames' => $this->getExceptionFrames(), |
|
| 179 | + 'tables' => $this->getProcessTables($tables), |
|
| 180 | + ]; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * The way in which the data sender (usually the server) can tell the recipient |
|
| 185 | - * (the browser, in general) what type of data is being sent in this case, html format tagged. |
|
| 186 | - * |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function contentType() |
|
| 190 | - { |
|
| 191 | - return 'text/html;charset=UTF-8'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Gets the brand of project. |
|
| 196 | - * |
|
| 197 | - * @return string |
|
| 198 | - */ |
|
| 199 | - public function getBrand() |
|
| 200 | - { |
|
| 201 | - return $this->brand; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Returns the default tables. |
|
| 206 | - * |
|
| 207 | - * @return \Syscodes\Contracts\Debug\Table[] |
|
| 208 | - */ |
|
| 209 | - protected function getDefaultTables() |
|
| 210 | - { |
|
| 211 | - return [ |
|
| 212 | - new ArrayTable('GET Data', $_GET), |
|
| 213 | - new ArrayTable('POST Data', $_POST), |
|
| 214 | - new ArrayTable('Files', $_FILES), |
|
| 215 | - new ArrayTable('Cookie', $_COOKIE), |
|
| 216 | - new ArrayTable('Session', isset($_SESSION) ? $_SESSION : []), |
|
| 217 | - new ArrayTable('Server/Request Data', $_SERVER), |
|
| 218 | - new ArrayTable(__('exception.environmentVars'), $_ENV), |
|
| 219 | - ]; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Get the code of the exception that is currently being handled. |
|
| 224 | - * |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - protected function getExceptionCode() |
|
| 228 | - { |
|
| 229 | - $exception = $this->getException(); |
|
| 230 | - $code = $exception->getCode(); |
|
| 231 | - |
|
| 232 | - if ($exception instanceof ErrorException) |
|
| 233 | - { |
|
| 234 | - $code = Misc::translateErrorCode($exception->getSeverity()); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - return (string) $code; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Get the stack trace frames of the exception that is currently being handled. |
|
| 242 | - * |
|
| 243 | - * @return \Syscodes\Debug\Engine\Supervisor; |
|
| 244 | - */ |
|
| 245 | - protected function getExceptionFrames() |
|
| 246 | - { |
|
| 247 | - $frames = $this->getSupervisor()->getFrames(); |
|
| 183 | + /** |
|
| 184 | + * The way in which the data sender (usually the server) can tell the recipient |
|
| 185 | + * (the browser, in general) what type of data is being sent in this case, html format tagged. |
|
| 186 | + * |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function contentType() |
|
| 190 | + { |
|
| 191 | + return 'text/html;charset=UTF-8'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Gets the brand of project. |
|
| 196 | + * |
|
| 197 | + * @return string |
|
| 198 | + */ |
|
| 199 | + public function getBrand() |
|
| 200 | + { |
|
| 201 | + return $this->brand; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Returns the default tables. |
|
| 206 | + * |
|
| 207 | + * @return \Syscodes\Contracts\Debug\Table[] |
|
| 208 | + */ |
|
| 209 | + protected function getDefaultTables() |
|
| 210 | + { |
|
| 211 | + return [ |
|
| 212 | + new ArrayTable('GET Data', $_GET), |
|
| 213 | + new ArrayTable('POST Data', $_POST), |
|
| 214 | + new ArrayTable('Files', $_FILES), |
|
| 215 | + new ArrayTable('Cookie', $_COOKIE), |
|
| 216 | + new ArrayTable('Session', isset($_SESSION) ? $_SESSION : []), |
|
| 217 | + new ArrayTable('Server/Request Data', $_SERVER), |
|
| 218 | + new ArrayTable(__('exception.environmentVars'), $_ENV), |
|
| 219 | + ]; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Get the code of the exception that is currently being handled. |
|
| 224 | + * |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + protected function getExceptionCode() |
|
| 228 | + { |
|
| 229 | + $exception = $this->getException(); |
|
| 230 | + $code = $exception->getCode(); |
|
| 231 | + |
|
| 232 | + if ($exception instanceof ErrorException) |
|
| 233 | + { |
|
| 234 | + $code = Misc::translateErrorCode($exception->getSeverity()); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + return (string) $code; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Get the stack trace frames of the exception that is currently being handled. |
|
| 242 | + * |
|
| 243 | + * @return \Syscodes\Debug\Engine\Supervisor; |
|
| 244 | + */ |
|
| 245 | + protected function getExceptionFrames() |
|
| 246 | + { |
|
| 247 | + $frames = $this->getSupervisor()->getFrames(); |
|
| 248 | 248 | |
| 249 | - return $frames; |
|
| 250 | - } |
|
| 249 | + return $frames; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - /** |
|
| 253 | - * Gets the page title web. |
|
| 254 | - * |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getPageTitle() |
|
| 258 | - { |
|
| 259 | - return $this->pageTitle; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Processes an array of tables making sure everything is allright. |
|
| 264 | - * |
|
| 265 | - * @param \Syscodes\Contracts\Debug\Table[] $tables |
|
| 266 | - * |
|
| 267 | - * @return array |
|
| 268 | - */ |
|
| 269 | - protected function getProcessTables(array $tables) |
|
| 270 | - { |
|
| 271 | - $processTables = []; |
|
| 272 | - |
|
| 273 | - foreach ($tables as $table) |
|
| 274 | - { |
|
| 275 | - if ( ! $table instanceof Table) |
|
| 276 | - { |
|
| 277 | - continue; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - $label = $table->getLabel(); |
|
| 281 | - |
|
| 282 | - try |
|
| 283 | - { |
|
| 284 | - $data = $table->getData(); |
|
| 285 | - |
|
| 286 | - if ( ! (is_array($data) || $data instanceof Traversable)) |
|
| 287 | - { |
|
| 288 | - $data = []; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - catch (Exception $e) |
|
| 292 | - { |
|
| 293 | - $data = []; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $processTables[$label] = $data; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - return $processTables; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Finds a resource, by its relative path, in all available search paths. |
|
| 304 | - * |
|
| 305 | - * @param string $resource |
|
| 306 | - * |
|
| 307 | - * @return string |
|
| 308 | - * |
|
| 309 | - * @throws \RuntimeException |
|
| 310 | - */ |
|
| 311 | - protected function getResource($resource) |
|
| 312 | - { |
|
| 313 | - if (isset($this->resourceCache[$resource])) |
|
| 314 | - { |
|
| 315 | - return $this->resourceCache[$resource]; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - foreach ($this->searchPaths as $path) |
|
| 319 | - { |
|
| 320 | - $fullPath = $path.DIRECTORY_SEPARATOR.$resource; |
|
| 321 | - |
|
| 322 | - if (is_file($fullPath)) |
|
| 323 | - { |
|
| 324 | - // Cache: |
|
| 325 | - $this->resourceCache[$resource] = $fullPath; |
|
| 326 | - |
|
| 327 | - return $fullPath; |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - throw new RuntimeException( |
|
| 332 | - "Could not find resource '{$resource}' in any resource paths.". |
|
| 333 | - "(searched: ".join(", ", $this->searchPaths).")"); |
|
| 334 | - } |
|
| 252 | + /** |
|
| 253 | + * Gets the page title web. |
|
| 254 | + * |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getPageTitle() |
|
| 258 | + { |
|
| 259 | + return $this->pageTitle; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Processes an array of tables making sure everything is allright. |
|
| 264 | + * |
|
| 265 | + * @param \Syscodes\Contracts\Debug\Table[] $tables |
|
| 266 | + * |
|
| 267 | + * @return array |
|
| 268 | + */ |
|
| 269 | + protected function getProcessTables(array $tables) |
|
| 270 | + { |
|
| 271 | + $processTables = []; |
|
| 272 | + |
|
| 273 | + foreach ($tables as $table) |
|
| 274 | + { |
|
| 275 | + if ( ! $table instanceof Table) |
|
| 276 | + { |
|
| 277 | + continue; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + $label = $table->getLabel(); |
|
| 281 | + |
|
| 282 | + try |
|
| 283 | + { |
|
| 284 | + $data = $table->getData(); |
|
| 285 | + |
|
| 286 | + if ( ! (is_array($data) || $data instanceof Traversable)) |
|
| 287 | + { |
|
| 288 | + $data = []; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + catch (Exception $e) |
|
| 292 | + { |
|
| 293 | + $data = []; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $processTables[$label] = $data; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + return $processTables; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Finds a resource, by its relative path, in all available search paths. |
|
| 304 | + * |
|
| 305 | + * @param string $resource |
|
| 306 | + * |
|
| 307 | + * @return string |
|
| 308 | + * |
|
| 309 | + * @throws \RuntimeException |
|
| 310 | + */ |
|
| 311 | + protected function getResource($resource) |
|
| 312 | + { |
|
| 313 | + if (isset($this->resourceCache[$resource])) |
|
| 314 | + { |
|
| 315 | + return $this->resourceCache[$resource]; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + foreach ($this->searchPaths as $path) |
|
| 319 | + { |
|
| 320 | + $fullPath = $path.DIRECTORY_SEPARATOR.$resource; |
|
| 321 | + |
|
| 322 | + if (is_file($fullPath)) |
|
| 323 | + { |
|
| 324 | + // Cache: |
|
| 325 | + $this->resourceCache[$resource] = $fullPath; |
|
| 326 | + |
|
| 327 | + return $fullPath; |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + throw new RuntimeException( |
|
| 332 | + "Could not find resource '{$resource}' in any resource paths.". |
|
| 333 | + "(searched: ".join(", ", $this->searchPaths).")"); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - /** |
|
| 337 | - * Given an exception and status code will display the error to the client. |
|
| 338 | - * |
|
| 339 | - * @return int|null |
|
| 340 | - */ |
|
| 341 | - public function handle() |
|
| 342 | - { |
|
| 343 | - $templatePath = $this->getResource('debug.layout.php'); |
|
| 344 | - |
|
| 345 | - $vars = $this->collectionVars(); |
|
| 336 | + /** |
|
| 337 | + * Given an exception and status code will display the error to the client. |
|
| 338 | + * |
|
| 339 | + * @return int|null |
|
| 340 | + */ |
|
| 341 | + public function handle() |
|
| 342 | + { |
|
| 343 | + $templatePath = $this->getResource('debug.layout.php'); |
|
| 344 | + |
|
| 345 | + $vars = $this->collectionVars(); |
|
| 346 | 346 | |
| 347 | - if (empty($vars['message'])) $vars['message'] = __('exception.noMessage'); |
|
| 347 | + if (empty($vars['message'])) $vars['message'] = __('exception.noMessage'); |
|
| 348 | 348 | |
| 349 | - $this->template->setVariables($vars); |
|
| 350 | - $this->template->render($templatePath); |
|
| 349 | + $this->template->setVariables($vars); |
|
| 350 | + $this->template->render($templatePath); |
|
| 351 | 351 | |
| 352 | - return MainHandler::QUIT; |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - /** |
|
| 356 | - * Set the editor to use to open referenced files, by a string identifier or callable |
|
| 357 | - * that will be executed for every file reference. Should return a string. |
|
| 358 | - * |
|
| 359 | - * @example $debug->setEditor(function($file, $line) { return "file:///{$file}"; }); |
|
| 360 | - * @example $debug->setEditor('vscode'); |
|
| 361 | - * |
|
| 362 | - * @param string $editor |
|
| 363 | - * |
|
| 364 | - * @return void |
|
| 365 | - * |
|
| 366 | - * @throws \InvalidArgumentException |
|
| 367 | - */ |
|
| 368 | - public function setEditor($editor) |
|
| 369 | - { |
|
| 370 | - if ( ! is_callable($editor) && ! isset($this->editors[$editor])) |
|
| 371 | - { |
|
| 372 | - throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " . |
|
| 373 | - implode(', ', array_keys($this->editors)) |
|
| 374 | - ); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - $this->editor = $editor; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Given a string file path, and an integer file line, |
|
| 382 | - * executes the editor resolver and returns. |
|
| 383 | - * |
|
| 384 | - * @param string $file |
|
| 385 | - * @param int $line |
|
| 386 | - * |
|
| 387 | - * @return string|bool |
|
| 388 | - * |
|
| 389 | - * @throws \UnexpectedValueException |
|
| 390 | - */ |
|
| 391 | - public function getEditorAtHref($file, $line) |
|
| 392 | - { |
|
| 393 | - $editor = $this->getEditor($file, $line); |
|
| 394 | - |
|
| 395 | - if (empty($editor)) |
|
| 396 | - { |
|
| 397 | - return false; |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if ( ! isset($editor['url']) || ! is_string($editor['url'])) |
|
| 401 | - { |
|
| 402 | - throw new UnexpectedValueException(__METHOD__.'should always resolve to a string or a valid editor array'); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - $editor['url'] = str_replace("%file", rawurldecode($file), $editor['url']); |
|
| 406 | - $editor['url'] = str_replace("%line", rawurldecode($line), $editor['url']); |
|
| 407 | - |
|
| 408 | - return $editor['url']; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * The editor must be a valid callable function/closure. |
|
| 413 | - * |
|
| 414 | - * @param string $file |
|
| 415 | - * @param int $line |
|
| 416 | - * |
|
| 417 | - * @return array |
|
| 418 | - */ |
|
| 419 | - protected function getEditor($file, $line) |
|
| 420 | - { |
|
| 421 | - if ( ! $this->editor || ( ! is_string($this->editor) && ! is_callable($this->editor))) |
|
| 422 | - { |
|
| 423 | - return []; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - if (is_string($this->editor) && isset($this->editors[$this->editor]) && ! is_callable($this->editors[$this->editor])) |
|
| 427 | - { |
|
| 428 | - return ['url' => $this->editors[$this->editor]]; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) |
|
| 432 | - { |
|
| 433 | - if (is_callable($this->editor)) |
|
| 434 | - { |
|
| 435 | - $callback = call_user_func($this->editor, $filePath, $line); |
|
| 436 | - } |
|
| 437 | - else |
|
| 438 | - { |
|
| 439 | - $callback = call_user_func($this->editors[$this->editor], $filePath, $line); |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - if (empty($callback)) |
|
| 443 | - { |
|
| 444 | - return []; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (is_string($callback)) |
|
| 448 | - { |
|
| 449 | - return ['url' => $callback]; |
|
| 450 | - } |
|
| 352 | + return MainHandler::QUIT; |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + /** |
|
| 356 | + * Set the editor to use to open referenced files, by a string identifier or callable |
|
| 357 | + * that will be executed for every file reference. Should return a string. |
|
| 358 | + * |
|
| 359 | + * @example $debug->setEditor(function($file, $line) { return "file:///{$file}"; }); |
|
| 360 | + * @example $debug->setEditor('vscode'); |
|
| 361 | + * |
|
| 362 | + * @param string $editor |
|
| 363 | + * |
|
| 364 | + * @return void |
|
| 365 | + * |
|
| 366 | + * @throws \InvalidArgumentException |
|
| 367 | + */ |
|
| 368 | + public function setEditor($editor) |
|
| 369 | + { |
|
| 370 | + if ( ! is_callable($editor) && ! isset($this->editors[$editor])) |
|
| 371 | + { |
|
| 372 | + throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " . |
|
| 373 | + implode(', ', array_keys($this->editors)) |
|
| 374 | + ); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + $this->editor = $editor; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Given a string file path, and an integer file line, |
|
| 382 | + * executes the editor resolver and returns. |
|
| 383 | + * |
|
| 384 | + * @param string $file |
|
| 385 | + * @param int $line |
|
| 386 | + * |
|
| 387 | + * @return string|bool |
|
| 388 | + * |
|
| 389 | + * @throws \UnexpectedValueException |
|
| 390 | + */ |
|
| 391 | + public function getEditorAtHref($file, $line) |
|
| 392 | + { |
|
| 393 | + $editor = $this->getEditor($file, $line); |
|
| 394 | + |
|
| 395 | + if (empty($editor)) |
|
| 396 | + { |
|
| 397 | + return false; |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if ( ! isset($editor['url']) || ! is_string($editor['url'])) |
|
| 401 | + { |
|
| 402 | + throw new UnexpectedValueException(__METHOD__.'should always resolve to a string or a valid editor array'); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + $editor['url'] = str_replace("%file", rawurldecode($file), $editor['url']); |
|
| 406 | + $editor['url'] = str_replace("%line", rawurldecode($line), $editor['url']); |
|
| 407 | + |
|
| 408 | + return $editor['url']; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * The editor must be a valid callable function/closure. |
|
| 413 | + * |
|
| 414 | + * @param string $file |
|
| 415 | + * @param int $line |
|
| 416 | + * |
|
| 417 | + * @return array |
|
| 418 | + */ |
|
| 419 | + protected function getEditor($file, $line) |
|
| 420 | + { |
|
| 421 | + if ( ! $this->editor || ( ! is_string($this->editor) && ! is_callable($this->editor))) |
|
| 422 | + { |
|
| 423 | + return []; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + if (is_string($this->editor) && isset($this->editors[$this->editor]) && ! is_callable($this->editors[$this->editor])) |
|
| 427 | + { |
|
| 428 | + return ['url' => $this->editors[$this->editor]]; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (is_callable($this->editor) || (isset($this->editors[$this->editor]) && is_callable($this->editors[$this->editor]))) |
|
| 432 | + { |
|
| 433 | + if (is_callable($this->editor)) |
|
| 434 | + { |
|
| 435 | + $callback = call_user_func($this->editor, $filePath, $line); |
|
| 436 | + } |
|
| 437 | + else |
|
| 438 | + { |
|
| 439 | + $callback = call_user_func($this->editors[$this->editor], $filePath, $line); |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + if (empty($callback)) |
|
| 443 | + { |
|
| 444 | + return []; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (is_string($callback)) |
|
| 448 | + { |
|
| 449 | + return ['url' => $callback]; |
|
| 450 | + } |
|
| 451 | 451 | |
| 452 | - return ['url' => isset($callback['url']) ? $callback['url'] : $callback]; |
|
| 453 | - } |
|
| 452 | + return ['url' => isset($callback['url']) ? $callback['url'] : $callback]; |
|
| 453 | + } |
|
| 454 | 454 | |
| 455 | - return []; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - /** |
|
| 459 | - * Registered the editor. |
|
| 460 | - * |
|
| 461 | - * @return string |
|
| 462 | - */ |
|
| 463 | - public function getEditorcode() |
|
| 464 | - { |
|
| 465 | - return $this->editor; |
|
| 466 | - } |
|
| 455 | + return []; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + /** |
|
| 459 | + * Registered the editor. |
|
| 460 | + * |
|
| 461 | + * @return string |
|
| 462 | + */ |
|
| 463 | + public function getEditorcode() |
|
| 464 | + { |
|
| 465 | + return $this->editor; |
|
| 466 | + } |
|
| 467 | 467 | |
| 468 | - /** |
|
| 469 | - * Sets the brand of project. |
|
| 470 | - * |
|
| 471 | - * @param string $brand |
|
| 472 | - * |
|
| 473 | - * @return void |
|
| 474 | - */ |
|
| 475 | - public function setBrand($brand) |
|
| 476 | - { |
|
| 477 | - $this->brand = (string) $brand; |
|
| 478 | - } |
|
| 468 | + /** |
|
| 469 | + * Sets the brand of project. |
|
| 470 | + * |
|
| 471 | + * @param string $brand |
|
| 472 | + * |
|
| 473 | + * @return void |
|
| 474 | + */ |
|
| 475 | + public function setBrand($brand) |
|
| 476 | + { |
|
| 477 | + $this->brand = (string) $brand; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Sets the page title web. |
|
| 482 | - * |
|
| 483 | - * @param string $title |
|
| 484 | - * |
|
| 485 | - * @return void |
|
| 486 | - */ |
|
| 487 | - public function setPageTitle($title) |
|
| 488 | - { |
|
| 489 | - $this->pageTitle = (string) $title; |
|
| 490 | - } |
|
| 480 | + /** |
|
| 481 | + * Sets the page title web. |
|
| 482 | + * |
|
| 483 | + * @param string $title |
|
| 484 | + * |
|
| 485 | + * @return void |
|
| 486 | + */ |
|
| 487 | + public function setPageTitle($title) |
|
| 488 | + { |
|
| 489 | + $this->pageTitle = (string) $title; |
|
| 490 | + } |
|
| 491 | 491 | } |
| 492 | 492 | \ No newline at end of file |
@@ -369,7 +369,7 @@ |
||
| 369 | 369 | { |
| 370 | 370 | if ( ! is_callable($editor) && ! isset($this->editors[$editor])) |
| 371 | 371 | { |
| 372 | - throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: " . |
|
| 372 | + throw new InvalidArgumentException("Unknown editor identifier: [{$editor}]. Known editors: ". |
|
| 373 | 373 | implode(', ', array_keys($this->editors)) |
| 374 | 374 | ); |
| 375 | 375 | } |
@@ -287,8 +287,7 @@ discard block |
||
| 287 | 287 | { |
| 288 | 288 | $data = []; |
| 289 | 289 | } |
| 290 | - } |
|
| 291 | - catch (Exception $e) |
|
| 290 | + } catch (Exception $e) |
|
| 292 | 291 | { |
| 293 | 292 | $data = []; |
| 294 | 293 | } |
@@ -344,7 +343,9 @@ discard block |
||
| 344 | 343 | |
| 345 | 344 | $vars = $this->collectionVars(); |
| 346 | 345 | |
| 347 | - if (empty($vars['message'])) $vars['message'] = __('exception.noMessage'); |
|
| 346 | + if (empty($vars['message'])) { |
|
| 347 | + $vars['message'] = __('exception.noMessage'); |
|
| 348 | + } |
|
| 348 | 349 | |
| 349 | 350 | $this->template->setVariables($vars); |
| 350 | 351 | $this->template->render($templatePath); |
@@ -433,8 +434,7 @@ discard block |
||
| 433 | 434 | if (is_callable($this->editor)) |
| 434 | 435 | { |
| 435 | 436 | $callback = call_user_func($this->editor, $filePath, $line); |
| 436 | - } |
|
| 437 | - else |
|
| 437 | + } else |
|
| 438 | 438 | { |
| 439 | 439 | $callback = call_user_func($this->editors[$this->editor], $filePath, $line); |
| 440 | 440 | } |
@@ -37,8 +37,11 @@ |
||
| 37 | 37 | <div id="frame-code-args-<?=$index?>" class="code-block frame-args"> |
| 38 | 38 | <?= $frameArgs ?> |
| 39 | 39 | </div> |
| 40 | - <?php else: ?> |
|
| 40 | + <?php else { |
|
| 41 | + : ?> |
|
| 41 | 42 | <div class="frame-noArgument"><?= e(__('exception.noArguments')) ?></div> |
| 42 | - <?php endif; ?> |
|
| 43 | + <?php endif; |
|
| 44 | +} |
|
| 45 | +?> |
|
| 43 | 46 | </div> |
| 44 | 47 | <?php endforeach; ?> |
| 45 | 48 | \ No newline at end of file |
@@ -21,10 +21,13 @@ |
||
| 21 | 21 | <?php endforeach; ?> |
| 22 | 22 | </tbody> |
| 23 | 23 | </table> |
| 24 | - <?php else : ?> |
|
| 24 | + <?php else { |
|
| 25 | + : ?> |
|
| 25 | 26 | <label class="empty"><?= e($label) ?></label> |
| 26 | 27 | <span class="empty"><?= e(__('exception.empty')) ?></span> |
| 27 | - <?php endif; ?> |
|
| 28 | + <?php endif; |
|
| 29 | +} |
|
| 30 | +?> |
|
| 28 | 31 | </div> |
| 29 | 32 | <?php endforeach; ?> |
| 30 | 33 | </div> |
@@ -12,7 +12,8 @@ discard block |
||
| 12 | 12 | <div class="frame-info-class"> |
| 13 | 13 | <?php if ($frame->getClass() == '') : ?> |
| 14 | 14 | <span class="frame-function"><?= e($frame->getFunction()) ?></span> |
| 15 | - <?php else: ?> |
|
| 15 | + <?php else { |
|
| 16 | + : ?> |
|
| 16 | 17 | <span class="frame-class"><?= e($frame->getClass()) ?></span> |
| 17 | 18 | <?php if ($frame->getFunction() != '') : ?> |
| 18 | 19 | <span class="frame-function"><?= e($frame->getFunction()) ?></span> |
@@ -26,5 +27,7 @@ discard block |
||
| 26 | 27 | </div> |
| 27 | 28 | |
| 28 | 29 | </div> |
| 29 | -<?php endforeach; ?> |
|
| 30 | +<?php endforeach; |
|
| 31 | +} |
|
| 32 | +?> |
|
| 30 | 33 | </div> |
| 31 | 34 | \ No newline at end of file |
@@ -4,9 +4,12 @@ |
||
| 4 | 4 | <?php foreach ($class as $i => $name) : ?> |
| 5 | 5 | <?php if ($i == count($class) - 1): ?> |
| 6 | 6 | <h1><?= $template->escape($name) ?></h1> |
| 7 | - <?php else: ?> |
|
| 7 | + <?php else { |
|
| 8 | + : ?> |
|
| 8 | 9 | <?= $template->escape($name).' \\' ?> |
| 9 | - <?php endif; ?> |
|
| 10 | + <?php endif; |
|
| 11 | +} |
|
| 12 | +?> |
|
| 10 | 13 | <?php endforeach; ?> |
| 11 | 14 | <?php if ($code): ?> |
| 12 | 15 | <span class="subtitle" title="Exception Code">(<?= $template->escape($code) ?>)</span> |
@@ -32,160 +32,160 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class Supervisor |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * Get exception. |
|
| 37 | - * |
|
| 38 | - * @var \Throwable $exception |
|
| 39 | - */ |
|
| 40 | - protected $exception; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The frame execute errors. |
|
| 44 | - * |
|
| 45 | - * @var string $frames |
|
| 46 | - */ |
|
| 47 | - protected $frames; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Constructor. The Supervisor class instance. |
|
| 51 | - * |
|
| 52 | - * @param \Throwable $exception |
|
| 53 | - * |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 56 | - public function __construct($exception) |
|
| 57 | - { |
|
| 58 | - $this->exception = $exception; |
|
| 59 | - } |
|
| 35 | + /** |
|
| 36 | + * Get exception. |
|
| 37 | + * |
|
| 38 | + * @var \Throwable $exception |
|
| 39 | + */ |
|
| 40 | + protected $exception; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The frame execute errors. |
|
| 44 | + * |
|
| 45 | + * @var string $frames |
|
| 46 | + */ |
|
| 47 | + protected $frames; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Constructor. The Supervisor class instance. |
|
| 51 | + * |
|
| 52 | + * @param \Throwable $exception |
|
| 53 | + * |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | + public function __construct($exception) |
|
| 57 | + { |
|
| 58 | + $this->exception = $exception; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Returns an iterator for the inspected exception's frames. |
|
| 63 | - * |
|
| 64 | - * @param \Throwable $exception |
|
| 65 | - * |
|
| 66 | - * @return array |
|
| 67 | - */ |
|
| 68 | - public function getFrames() |
|
| 69 | - { |
|
| 70 | - if ($this->frames === null) |
|
| 71 | - { |
|
| 72 | - $frames = $this->getTrace($this->exception); |
|
| 73 | - |
|
| 74 | - // Fill empty line/file info for call_user_func_array usages |
|
| 75 | - foreach ($frames as $k => $frame) |
|
| 76 | - { |
|
| 77 | - if (empty($frame['file'])) |
|
| 78 | - { |
|
| 79 | - // Default values when file and line are missing |
|
| 80 | - $file = '[PHP internal Code]'; |
|
| 81 | - $line = 0; |
|
| 82 | - $next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : []; |
|
| 83 | - $frames[$k]['file'] = $file; |
|
| 84 | - $frames[$k]['line'] = $line; |
|
| 85 | - } |
|
| 86 | - } |
|
| 61 | + /** |
|
| 62 | + * Returns an iterator for the inspected exception's frames. |
|
| 63 | + * |
|
| 64 | + * @param \Throwable $exception |
|
| 65 | + * |
|
| 66 | + * @return array |
|
| 67 | + */ |
|
| 68 | + public function getFrames() |
|
| 69 | + { |
|
| 70 | + if ($this->frames === null) |
|
| 71 | + { |
|
| 72 | + $frames = $this->getTrace($this->exception); |
|
| 73 | + |
|
| 74 | + // Fill empty line/file info for call_user_func_array usages |
|
| 75 | + foreach ($frames as $k => $frame) |
|
| 76 | + { |
|
| 77 | + if (empty($frame['file'])) |
|
| 78 | + { |
|
| 79 | + // Default values when file and line are missing |
|
| 80 | + $file = '[PHP internal Code]'; |
|
| 81 | + $line = 0; |
|
| 82 | + $next_frame = ! empty($frames[$k + 1]) ? $frames[$k + 1] : []; |
|
| 83 | + $frames[$k]['file'] = $file; |
|
| 84 | + $frames[$k]['line'] = $line; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - // Find latest non-error handling frame index ($i) used to remove error handling frames |
|
| 89 | - $i = 0; |
|
| 90 | - |
|
| 91 | - foreach ($frames as $k => $frame) |
|
| 92 | - { |
|
| 93 | - if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) |
|
| 94 | - { |
|
| 95 | - $i = $k; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - // Remove error handling frames |
|
| 99 | - if ($i > 0) |
|
| 100 | - { |
|
| 101 | - array_splice($frames, 0, $i); |
|
| 102 | - } |
|
| 88 | + // Find latest non-error handling frame index ($i) used to remove error handling frames |
|
| 89 | + $i = 0; |
|
| 90 | + |
|
| 91 | + foreach ($frames as $k => $frame) |
|
| 92 | + { |
|
| 93 | + if ($frame['file'] == $this->exception->getFile() && $frame['line'] == $this->exception->getLine()) |
|
| 94 | + { |
|
| 95 | + $i = $k; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + // Remove error handling frames |
|
| 99 | + if ($i > 0) |
|
| 100 | + { |
|
| 101 | + array_splice($frames, 0, $i); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $firstFrame = $this->getFrameFromException($this->exception); |
|
| 105 | - array_unshift($frames, $firstFrame); |
|
| 106 | - |
|
| 107 | - $this->frames = new Collection($frames); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $this->frames; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Given an exception, generates an array in the format generated by Exception::getTrace(). |
|
| 115 | - * |
|
| 116 | - * @param \Throwable $exception |
|
| 117 | - * |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - protected function getFrameFromException(Throwable $exception) |
|
| 121 | - { |
|
| 122 | - return [ |
|
| 123 | - 'file' => $exception->getFile(), |
|
| 124 | - 'line' => $exception->getLine(), |
|
| 125 | - 'class' => get_class($exception), |
|
| 126 | - 'code' => $exception->getCode(), |
|
| 127 | - 'args' => [ |
|
| 128 | - $exception->getMessage(), |
|
| 129 | - ], |
|
| 130 | - ]; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Gets exception already specified. |
|
| 135 | - * |
|
| 136 | - * @return \Throwable |
|
| 137 | - */ |
|
| 138 | - public function getException() |
|
| 139 | - { |
|
| 140 | - return $this->exception; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Gets the message of exception. |
|
| 145 | - * |
|
| 146 | - * @return string |
|
| 147 | - */ |
|
| 148 | - public function getExceptionMessage() |
|
| 149 | - { |
|
| 150 | - return $this->exception->getMessage(); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Gets the class name of exception. |
|
| 155 | - * |
|
| 156 | - * @return string |
|
| 157 | - */ |
|
| 158 | - public function getExceptionName() |
|
| 159 | - { |
|
| 160 | - return getClass($this->exception); |
|
| 161 | - } |
|
| 104 | + $firstFrame = $this->getFrameFromException($this->exception); |
|
| 105 | + array_unshift($frames, $firstFrame); |
|
| 106 | + |
|
| 107 | + $this->frames = new Collection($frames); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $this->frames; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Given an exception, generates an array in the format generated by Exception::getTrace(). |
|
| 115 | + * |
|
| 116 | + * @param \Throwable $exception |
|
| 117 | + * |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + protected function getFrameFromException(Throwable $exception) |
|
| 121 | + { |
|
| 122 | + return [ |
|
| 123 | + 'file' => $exception->getFile(), |
|
| 124 | + 'line' => $exception->getLine(), |
|
| 125 | + 'class' => get_class($exception), |
|
| 126 | + 'code' => $exception->getCode(), |
|
| 127 | + 'args' => [ |
|
| 128 | + $exception->getMessage(), |
|
| 129 | + ], |
|
| 130 | + ]; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Gets exception already specified. |
|
| 135 | + * |
|
| 136 | + * @return \Throwable |
|
| 137 | + */ |
|
| 138 | + public function getException() |
|
| 139 | + { |
|
| 140 | + return $this->exception; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Gets the message of exception. |
|
| 145 | + * |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | + public function getExceptionMessage() |
|
| 149 | + { |
|
| 150 | + return $this->exception->getMessage(); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Gets the class name of exception. |
|
| 155 | + * |
|
| 156 | + * @return string |
|
| 157 | + */ |
|
| 158 | + public function getExceptionName() |
|
| 159 | + { |
|
| 160 | + return getClass($this->exception); |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Gets the backtrace from an exception. |
|
| 165 | - * |
|
| 166 | - * @param \Throwable $exception |
|
| 167 | - * |
|
| 168 | - * @return array |
|
| 169 | - */ |
|
| 170 | - protected function getTrace($exception) |
|
| 171 | - { |
|
| 172 | - $traces = $exception->getTrace(); |
|
| 173 | - |
|
| 174 | - if ( ! $exception instanceof ErrorException) |
|
| 175 | - { |
|
| 176 | - return $traces; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if ( ! extension_loaded('xdebug') || ! xdebug_is_enabled()) |
|
| 180 | - { |
|
| 181 | - return []; |
|
| 182 | - } |
|
| 163 | + /** |
|
| 164 | + * Gets the backtrace from an exception. |
|
| 165 | + * |
|
| 166 | + * @param \Throwable $exception |
|
| 167 | + * |
|
| 168 | + * @return array |
|
| 169 | + */ |
|
| 170 | + protected function getTrace($exception) |
|
| 171 | + { |
|
| 172 | + $traces = $exception->getTrace(); |
|
| 173 | + |
|
| 174 | + if ( ! $exception instanceof ErrorException) |
|
| 175 | + { |
|
| 176 | + return $traces; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if ( ! extension_loaded('xdebug') || ! xdebug_is_enabled()) |
|
| 180 | + { |
|
| 181 | + return []; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - // Use xdebug to get the full stack trace and remove the shutdown handler stack trace |
|
| 185 | - $stack = array_reverse(xdebug_get_function_stack()); |
|
| 186 | - $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
| 187 | - $traces = array_diff_key($stack, $trace); |
|
| 184 | + // Use xdebug to get the full stack trace and remove the shutdown handler stack trace |
|
| 185 | + $stack = array_reverse(xdebug_get_function_stack()); |
|
| 186 | + $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); |
|
| 187 | + $traces = array_diff_key($stack, $trace); |
|
| 188 | 188 | |
| 189 | - return $traces; |
|
| 190 | - } |
|
| 189 | + return $traces; |
|
| 190 | + } |
|
| 191 | 191 | } |
| 192 | 192 | \ No newline at end of file |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | */ |
| 52 | 52 | public function __construct(array $frames) |
| 53 | 53 | { |
| 54 | - $this->frames = array_map(function ($frame) { |
|
| 54 | + $this->frames = array_map(function($frame) { |
|
| 55 | 55 | return new Frame($frame); |
| 56 | 56 | }, $frames); |
| 57 | 57 | } |