Files

63 lines
2.1 KiB
PHP

<?php
/**
* Non-production environment marker.
*
* Dev and prod are the same codebase on near-identical URLs, so it is genuinely
* easy to edit a real client's session while believing you are on dev. This
* paints an unmissable hazard frame around every page whenever APP_ENV is not
* 'prod', plus a corner chip naming the environment.
*
* Included from <head> in both includes/header.php (backoffice) and
* site/includes/head.php (public site). It hangs off html::before / html::after
* rather than a wrapper element, so no page markup has to change and nothing
* can shift the layout: the frame is fixed, on top, and click-through.
*
* Reads env() directly rather than the APP_ENV constant, because the public
* site does not always load config/functions.php.
*/
$_env = strtolower((string) (function_exists('env') ? env('APP_ENV', 'prod') : 'prod'));
if ($_env === 'prod' || $_env === 'production') return;
?>
<style>
/* Faixa de aviso de ambiente — só fora de produção. */
html::after {
content: '';
position: fixed;
inset: 0;
z-index: 2147483646;
pointer-events: none; /* nunca intercepta cliques */
border: 6px solid transparent;
border-image: repeating-linear-gradient(
45deg,
#111 0 14px,
#f5c400 14px 28px
) 6;
}
html::before {
content: '<?= htmlspecialchars(strtoupper($_env), ENT_QUOTES) ?>';
position: fixed;
top: 6px;
left: 50%;
transform: translateX(-50%);
z-index: 2147483647;
pointer-events: none;
padding: .1rem .8rem .15rem;
background: #f5c400;
color: #111;
font: 700 .7rem/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
letter-spacing: .18em;
border-radius: 0 0 .35rem .35rem;
box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}
/* Em ecrãs pequenos a moldura rouba demasiado espaço horizontal. */
@media (max-width: 575.98px) {
html::after { border-width: 4px; border-image-slice: 4; }
html::before { font-size: .6rem; top: 4px; }
}
/* Ao imprimir não faz sentido nenhum. */
@media print {
html::after, html::before { display: none; }
}
</style>