Browse Source

improve debugbar z-index

michelphp 2 weeks ago
parent
commit
9b4e9a9b46

+ 19 - 2
functions/helpers.php

@@ -176,6 +176,25 @@ if (!function_exists('redirect')) {
     }
 }
 
+if (!function_exists('redirect_to')) {
+    /**
+     * Creates a redirect response to a named route.
+     *
+     * @param string $routeName   The name of the route registered in the router.
+     * @param array  $parameters  Dynamic parameters to build the URI (e.g., ['id' => 1]).
+     * @param int    $status      The HTTP status code (default: 302).
+     * @return ResponseInterface The configured redirect response.
+     */
+    function redirect_to(string $routeName, array $parameters = [], int $status = 302): ResponseInterface
+    {
+        /** @var RouterInterface $router */
+        $router = container()->get(RouterInterface::class);
+        return response_factory()
+            ->createResponse($status)
+            ->withHeader('Location', $router->generateUri($routeName, $parameters));
+    }
+}
+
 if (!function_exists('render_view')) {
 
     /**
@@ -208,8 +227,6 @@ if (!function_exists('render')) {
      * @param array $context The context data to pass to the view.
      * @param int $status The HTTP status code.
      * @return ResponseInterface The HTTP response with the rendered view.
-     * @throws ContainerExceptionInterface
-     * @throws NotFoundExceptionInterface
      */
     function render(string $view, array $context = [], int $status = 200): ResponseInterface
     {

+ 1 - 0
resources/debug/debugbar.html.php

@@ -41,6 +41,7 @@
             height: 40px;
             font-family: Inter, sans-serif;
             white-space: nowrap;
+            z-index: 10000;
         }
 
         .__michel_debug_navbar a {

+ 3 - 1
resources/views/error.html.php

@@ -169,8 +169,9 @@ $e = $exception->getPrevious() ?: $exception;
             <p><?php echo $e->getMessage(); ?> - <small><?php echo get_class($e) ?></small></p>
             <i class="small"><?php echo $e->getFile(); ?> line <?php echo $e->getLine(); ?></i>
         </div>
+        <?php $traces = array_reverse($e->getTrace()); ?>
+        <?php if (!empty($traces)) : ?>
         <ul class="exception-traces">
-            <?php $traces = array_reverse($e->getTrace()); ?>
             <?php foreach (array_reverse($traces, true) as $key => $item): ?>
                 <?php if (!isset($item['file'])) {
                     continue;
@@ -189,6 +190,7 @@ $e = $exception->getPrevious() ?: $exception;
                 </li>
             <?php endforeach; ?>
         </ul>
+        <?php endif; ?>
     </div>
 </main>
 <footer>

+ 13 - 0
src/ErrorHandler/ErrorHandler.php

@@ -24,6 +24,19 @@ final class ErrorHandler
         $handler = new self();
         set_error_handler($handler);
         set_exception_handler([$handler, 'handleException']);
+        register_shutdown_function(function() use ($handler) {
+            $error = error_get_last();
+            if ($error !== null && in_array($error['type'], [E_ERROR, E_PARSE, E_COMPILE_ERROR])) {
+                $exception = new \ErrorException(
+                    $error['message'],
+                    0,
+                    $error['type'],
+                    $error['file'],
+                    $error['line'],
+                );
+                $handler->handleException($exception);
+            }
+        });
         return $handler;
     }