From a1f39fe7194a72b010c517a752b5307a61811475 Mon Sep 17 00:00:00 2001 From: Michael Ochmann Date: Fri, 9 Aug 2024 13:27:43 +0200 Subject: [PATCH] improved exception handler made it look more like laravel's `ignition` --- src/Application.php | 15 +- src/services/Request.php | 2 + views/LucidityException.mustache | 90 ++++- views/partials/LucidityHighlight.mustache | 380 ++++++++++++++++++++++ views/partials/LucidityLayout.mustache | 66 +++- 5 files changed, 536 insertions(+), 17 deletions(-) create mode 100644 views/partials/LucidityHighlight.mustache diff --git a/src/Application.php b/src/Application.php index b9734ff..74b4588 100644 --- a/src/Application.php +++ b/src/Application.php @@ -68,10 +68,21 @@ abstract class Application { self::View("LucidityException", [ "exception" => $exception, - "trace" => $exception->getTrace(), + "trace" => array_map(function($item, $index) use ($exception) { + $item["content"] = isset($item["file"]) && file_exists($item["file"]) ? json_encode(file_get_contents($item["file"])) : ""; + $item["id"] = $index; + if ($index === 0) { + $item["line"] = $exception->getLine(); + $item["file"] = $exception->getFile(); + $item["content"] = json_encode($exception->getFile() !== "" && file_exists($exception->getFile()) ? file_get_contents($exception->getFile()) : ""); + } + + return $item; + }, $exception->getTrace(), array_keys($exception->getTrace())), "exceptionType" => $exception::class, "lucidityVersion" => \Composer\InstalledVersions::getVersion("massivedynamic/lucidity"), - "phpVersion" => phpversion() + "phpVersion" => phpversion(), + "initialContent" =>"" ]); } diff --git a/src/services/Request.php b/src/services/Request.php index a346062..8928b90 100644 --- a/src/services/Request.php +++ b/src/services/Request.php @@ -2,6 +2,8 @@ namespace massivedynamic\lucidity\services; +use Exception; + use massivedynamic\lucidity\RequestType; use massivedynamic\lucidity\Utils; use massivedynamic\lucidity\services\Service; diff --git a/views/LucidityException.mustache b/views/LucidityException.mustache index 1cfd02b..6a1bb83 100644 --- a/views/LucidityException.mustache +++ b/views/LucidityException.mustache @@ -9,27 +9,99 @@

{{exception.getMessage}}

- {{#exception.getFile}} - {{.}}:{{exception.getLine}} - {{/exception.getFile}}
PHP {{phpVersion}} lucidity {{lucidityVersion}}
-
+
+ +
+ {{#exception.getFile}} + {{.}}:{{exception.getLine}} + {{/exception.getFile}} +
{{initialContent}}
+
+{{> LucidityHighlight}} + + + {{/content}} {{/LucidityLayout}} diff --git a/views/partials/LucidityHighlight.mustache b/views/partials/LucidityHighlight.mustache new file mode 100644 index 0000000..9fbaaf4 --- /dev/null +++ b/views/partials/LucidityHighlight.mustache @@ -0,0 +1,380 @@ + + + diff --git a/views/partials/LucidityLayout.mustache b/views/partials/LucidityLayout.mustache index 823179e..ddbb6a1 100644 --- a/views/partials/LucidityLayout.mustache +++ b/views/partials/LucidityLayout.mustache @@ -6,19 +6,22 @@ box-sizing: border-box; } + aside.list { + border-right: solid 1px #eee; + } + body { - font-family: sans-serif; + font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif, BlinkMacSystemFont, Helvetica Neue, Arial, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji; padding: 2rem; background: #e5e7eb; - color: #333; + color: #1f2937; } .badge { - background : #ddd; + background : #6b72800d; display: inline-block; padding: 0.5rem 1rem; border-radius: 4px; - font-weight: bold; color: #444; } @@ -27,6 +30,7 @@ box-shadow: 0 0 16px rgba(0, 0, 0, 0.3); margin-bottom: 4rem; position: relative; + border-radius: 0.5em; } .card:not(.edgeless) { padding: 2rem; @@ -36,13 +40,23 @@ padding: 1rem 2rem; transition: all 0.2s ease-in-out; } + .list-item:not(.active) { + cursor: pointer; + } + .list-item h3 { + margin: 0.5rem 0 0 0; + } .list-item:not(:last-of-type) { border-bottom : solid 1px #ddd; } .list-item:hover { - background: #dd524c; + background : #ef444433; } - .list-item:hover, .list-item:hover * { + + .list-item.active { + background: #ef4544; + } + .list-item.active, .list-item.active * { color: white !important; } @@ -65,6 +79,46 @@ .info * { flex: 1; } + + .grid { + display: grid; + } + .grid.thirty-seventy { + grid-template-columns: 1fr 3fr; + } + .hljs-ln-code { + padding-left: 2rem !important; + white-space: pre-wrap; + } + .hljs-ln tr td { + padding: 0.5rem 0; + } + + .code, .hljs { + background: #fcfcfd !important; + } + .code { + position: relative; + } + .code .file { + position: absolute; + top: 1rem; + right: 2rem; + } + + .hljs-ln-numbers { + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; + text-align: center; + color: #aaa; + vertical-align: top; + padding-right: 5px; + /* your custom style here */ + }