novaconium/src/functions.php

60 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* Dump and Die (debug function)
*
* @param mixed ...$vars Any number of variables to dump and then exit the script.
*/
function dd(...$vars): void {
echo "<pre style='background:#1e1e1e;color:#00ff00;padding:12px;border-radius:6px;font-size:14px;'>";
foreach ($vars as $var) {
var_dump($var);
echo "\n";
}
echo "</pre>";
exit;
}
/**
* Finalize the request lifecycle.
*
* This function safely writes session data, stores flash messages, closes the database
* connection if configured, and performs a redirect.
*/
function makeitso(): void {
global $session, $db, $redirect, $config, $messages, $log;
// ------------------------------
// Close database if configured
// ------------------------------
// Check if database configuration exists and the $db object is set
if (!empty($config['database']['host']) && isset($db)) {
// If the $db object has a close method, call it to close the connection
if (method_exists($db, 'close')) {
$db->close();
}
}
// ------------------------------
// Save flash messages to session
// ------------------------------
// Set all messages in the session
$session->set('messages', $messages->getAllMessages());
// Write any buffered session data to persistent storage
$session->write();
// ------------------------------
// Perform redirect
// ------------------------------
// Execute the redirect operation
$redirect->execute();
// Exit the script after processing is complete
exit;
}