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