get($name); } } if (!function_exists('app_set_container')) { /** * Set global container instance */ function app_set_container(object $container): void { $GLOBALS['__woles_container'] = $container; } } if (!function_exists('request')) { /** * Get request instance */ function request(): App\Core\Request { return app('request'); } } if (!function_exists('response')) { /** * Get response instance */ function response(): App\Core\Response { return app('response'); } } if (!function_exists('view')) { /** * Render a view */ function view(string $view, array $data = []): string { return app('view')->render($view, $data); } } if (!function_exists('redirect')) { /** * Redirect to URL */ function redirect(string $url, int $status = 302): void { response()->redirect($url, $status); } } if (!function_exists('env')) { /** * Get environment variable */ function env(string $key, $default = null) { $value = getenv($key); return $value !== false ? $value : $default; } } if (!function_exists('config')) { /** * Get configuration value */ function config(string $key, $default = null) { static $config = []; if (empty($config)) { $configFile = __DIR__ . '/Config/app.php'; if (file_exists($configFile)) { $config = include $configFile; } } $keys = explode('.', $key); $value = $config; foreach ($keys as $k) { if (is_array($value) && isset($value[$k])) { $value = $value[$k]; } else { return $default; } } return $value; } } if (!function_exists('csrf_token')) { /** * Generate CSRF token */ function csrf_token(): string { return app('security')->generateCsrfToken(); } } if (!function_exists('csrf_field')) { /** * Generate CSRF hidden field */ function csrf_field(): string { return ''; } } if (!function_exists('method_field')) { /** * Generate method field for forms */ function method_field(string $method): string { return ''; } } if (!function_exists('asset')) { /** * Generate asset URL */ function asset(string $path): string { $baseUrl = env('APP_URL', 'http://localhost:8000'); return rtrim($baseUrl, '/') . '/public/' . ltrim($path, '/'); } } if (!function_exists('url')) { /** * Generate URL */ function url(string $path = ''): string { $baseUrl = env('APP_URL', 'http://localhost:8000'); return rtrim($baseUrl, '/') . '/' . ltrim($path, '/'); } } if (!function_exists('route')) { /** * Generate route URL (placeholder for now) */ function route(string $name, array $params = []): string { // This would be implemented with a proper route name system return url($name); } } if (!function_exists('dd')) { /** * Dump and die */ function dd(...$vars): void { foreach ($vars as $var) { echo '
';
var_dump($var);
echo '';
}
die();
}
}
if (!function_exists('dump')) {
/**
* Dump variable
*/
function dump(...$vars): void
{
foreach ($vars as $var) {
echo '';
var_dump($var);
echo '';
}
}
}
if (!function_exists('old')) {
/**
* Get old input value
*/
function old(string $key, $default = null)
{
return $_SESSION['_old_input'][$key] ?? $default;
}
}
if (!function_exists('flash')) {
/**
* Set flash message
*/
function flash(string $key, $message): void
{
$_SESSION['_flash'][$key] = $message;
}
}
if (!function_exists('flash_get')) {
/**
* Get and remove flash message
*/
function flash_get(string $key)
{
$message = $_SESSION['_flash'][$key] ?? null;
unset($_SESSION['_flash'][$key]);
return $message;
}
}
if (!function_exists('e')) {
/**
* Escape HTML
*/
function e(string $value): string
{
return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}
}
if (!function_exists('str_random')) {
/**
* Generate random string
*/
function str_random(int $length = 32): string
{
return app('security')->generateRandomString($length);
}
}
if (!function_exists('bcrypt')) {
/**
* Hash password
*/
function bcrypt(string $password): string
{
return app('security')->hashPassword($password);
}
}
if (!function_exists('verify_password')) {
/**
* Verify password
*/
function verify_password(string $password, string $hash): bool
{
return app('security')->verifyPassword($password, $hash);
}
}