Update: 2026-05-03 17:32:57

This commit is contained in:
Hamza-Ayed
2026-05-03 17:32:57 +03:00
parent 6a3e66ad49
commit 4b40b1185f
102 changed files with 525 additions and 11371 deletions

19
app/bootstrap/auth.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
/**
* Global Auth State (Optional Helper)
*/
declare(strict_types=1);
// This can be used to store the current user globally if needed
// after successful middleware check.
$GLOBALS['current_user'] = null;
function current_user() {
return $GLOBALS['current_user'];
}
function set_current_user(array $user) {
$GLOBALS['current_user'] = $user;
}

21
app/bootstrap/env.php Normal file
View File

@@ -0,0 +1,21 @@
<?php
/**
* Simple .env Loader
*/
if (file_exists(ROOT_PATH . '/.env')) {
$lines = file(ROOT_PATH . '/.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
if (str_starts_with(trim($line), '#')) continue;
list($name, $value) = explode('=', $line, 2);
$name = trim($name);
$value = trim($value, " \t\n\r\0\x0B\"'");
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
putenv(sprintf('%s=%s', $name, $value));
$_ENV[$name] = $value;
$_SERVER[$name] = $value;
}
}
}

29
app/bootstrap/init.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
/**
* Simple Bootstrap Initialization
*/
declare(strict_types=1);
// 1. Constants
define('ROOT_PATH', dirname(__DIR__, 2));
define('APP_PATH', ROOT_PATH . '/app');
define('STORAGE_PATH', ROOT_PATH . '/storage');
// 2. Load Environment Variables
require_once APP_PATH . '/bootstrap/env.php';
// 3. Common Helpers
require_once APP_PATH . '/helpers/helpers.php';
// 4. Core Classes (Manual autoload for simplicity)
require_once APP_PATH . '/core/Database.php';
require_once APP_PATH . '/core/JWT.php';
require_once APP_PATH . '/core/Security.php';
require_once APP_PATH . '/core/Validator.php';
// 5. Response Utility
require_once APP_PATH . '/bootstrap/response.php';
// 6. Auth Session/State (Simple)
require_once APP_PATH . '/bootstrap/auth.php';

View File

@@ -0,0 +1,25 @@
<?php
/**
* Standardized JSON Responses
*/
function json_response(bool $success, $data = null, ?string $message = null, int $code = 200) {
header('Content-Type: application/json; charset=utf-8');
http_response_code($code);
echo json_encode([
'success' => $success,
'data' => $data,
'message' => $message,
'timestamp' => date('c')
], JSON_UNESCAPED_UNICODE);
exit;
}
function json_error(string $message, int $code = 400, $errors = null) {
json_response(false, $errors, $message, $code);
}
function json_success($data = null, ?string $message = 'Success', int $code = 200) {
json_response(true, $data, $message, $code);
}