Skip to content

Commit

Permalink
feat: implement public layout and unify error handling for improved u…
Browse files Browse the repository at this point in the history
…ser experience
  • Loading branch information
0x1026 committed Dec 12, 2024
1 parent 6e28550 commit 30c692e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 43 deletions.
18 changes: 10 additions & 8 deletions app/src/app/Core/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,21 @@ protected function handleMiddlewares(array $middlewares): void
throw new Exception("Middleware {$middlewareClass} must implement MiddlewareInterface");
}

$middleware->handle($_REQUEST, fn () => null);
$middleware->handle($_REQUEST, fn() => null);

Check warning on line 144 in app/src/app/Core/Router.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Core/Router.php#L144

Added line #L144 was not covered by tests
}
}

protected function abort(int $statusCode, string $message): void
{
if ($statusCode === 404) {
View::render([
'view' => 'Error/404',
'title' => 'Error 404',
'layout' => 'BlankLayout'
]);
}
View::render([
'view' => "Error",
'title' => "Error $statusCode",
'layout' => 'PublicLayout',
'data' => [
'code' => $statusCode,
'message' => $message,
],
]);

Check warning on line 158 in app/src/app/Core/Router.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Core/Router.php#L150-L158

Added lines #L150 - L158 were not covered by tests
http_response_code($statusCode);
exit;
}
Expand Down
20 changes: 1 addition & 19 deletions app/src/app/Layouts/BlankLayout.php
Original file line number Diff line number Diff line change
@@ -1,19 +1 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
<?= htmlspecialchars($title) . ' - ' . htmlspecialchars(getenv('APP_NAME')); ?>
</title>
<script src="/assets/js/app.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="/assets/css/app.css">
</head>

<body class="w-full h-full">
<?= $content; ?>
</body>

</html>
<?= $content;

Check warning on line 1 in app/src/app/Layouts/BlankLayout.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Layouts/BlankLayout.php#L1

Added line #L1 was not covered by tests
19 changes: 19 additions & 0 deletions app/src/app/Layouts/PublicLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">

Check warning on line 2 in app/src/app/Layouts/PublicLayout.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Layouts/PublicLayout.php#L1-L2

Added lines #L1 - L2 were not covered by tests

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
<?= $title . ' - ' . getenv('APP_NAME'); ?>
</title>
<script src="/assets/js/app.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="/assets/css/app.css">
</head>

Check warning on line 13 in app/src/app/Layouts/PublicLayout.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Layouts/PublicLayout.php#L4-L13

Added lines #L4 - L13 were not covered by tests

<body class="w-full h-full">
<?= $content; ?>
</body>

Check warning on line 17 in app/src/app/Layouts/PublicLayout.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Layouts/PublicLayout.php#L15-L17

Added lines #L15 - L17 were not covered by tests

</html>

Check warning on line 19 in app/src/app/Layouts/PublicLayout.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Layouts/PublicLayout.php#L19

Added line #L19 was not covered by tests
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<div class="min-h-screen bg-gray-100 flex items-center justify-center">
<div class="text-center">
<h1 class="text-9xl font-bold text-blue-500">403</h1>
<p class="mt-4 text-2xl font-semibold text-gray-700">Acceso Denegado</p>
<p class="mt-2 text-gray-500">Lo sentimos, la página a la que intentas acceder no está disponible para ti.</p>
<div class="mt-6">
<h1 class="text-9xl font-bold text-blue-500"><?= $code; ?></h1>
<p class="mt-4 text-3xl font-semibold text-gray-700"><?= $message; ?></p>

Check warning on line 4 in app/src/app/Views/Error.php

View check run for this annotation

Codecov / codecov/patch

app/src/app/Views/Error.php#L3-L4

Added lines #L3 - L4 were not covered by tests
<!-- <p class="mt-2 text-gray-500">Lo sentimos, la página que buscas no existe o fue movida.</p> -->
<div class="mt-8">
<a href="/" class="px-6 py-3 bg-blue-500 text-white font-medium rounded hover:bg-blue-600 transition">
Volver al Inicio
</a>
Expand Down
12 changes: 0 additions & 12 deletions app/src/app/Views/Error/404.php

This file was deleted.

0 comments on commit 30c692e

Please sign in to comment.