made the code more composer friendly
This commit is contained in:
@@ -1,29 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Dump and Die
|
||||
* Dump and Die (debug function)
|
||||
*
|
||||
* @param mixed ...$vars Any number of variables to dump and then exit the script.
|
||||
*/
|
||||
function dd(...$vars) {
|
||||
echo "<pre style='background:#222;color:#0f0;padding:10px;border-radius:5px;'>";
|
||||
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>";
|
||||
die();
|
||||
exit;
|
||||
}
|
||||
|
||||
function makeitso() {
|
||||
/**
|
||||
* 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;
|
||||
|
||||
if (!empty($config['database']['host'])) {
|
||||
$db->close();
|
||||
// ------------------------------
|
||||
// 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();
|
||||
}
|
||||
// Exit the script after processing is complete
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user