<?php

declare(strict_types=1);

$envPath = __DIR__ . '/../.env.php';
$exampleEnvPath = __DIR__ . '/../.env.example.php';
$config = is_file($envPath) ? require $envPath : require $exampleEnvPath;

function config(string $key, $default = null)
{
    global $config;

    return $config[$key] ?? $default;
}

function appUrl(string $path): string
{
    return rtrim((string) config('APP_BASE_URL'), '/') . '/' . ltrim($path, '/');
}

function ensureRuntimeDirectories(): void
{
    foreach ([__DIR__ . '/../storage/logs'] as $path) {
        if (!is_dir($path)) {
            mkdir($path, 0775, true);
        }
    }
}

ensureRuntimeDirectories();
