<?php
declare(strict_types=1);

if (!function_exists('h')) {
  function h(string $s): string {
    return htmlspecialchars($s, ENT_QUOTES, 'UTF-8');
  }
}

if (!function_exists('app_base')) {
  function app_base(string $path = ''): string {
    $base = cfg()['app']['base_url'] ?? '';
    $base = rtrim((string)$base, '/');
    return $base . '/' . ltrim($path, '/');
  }
}

if (!function_exists('start_app_session')) {
  function start_app_session(): void {
    $name = cfg()['app']['session_name'] ?? 'app_sess';

    // Eğer session zaten başladıysa tekrar dokunma
    if (session_status() === PHP_SESSION_ACTIVE) return;

    // session_name session_start'tan önce set edilmeli
    session_name((string)$name);

    session_start([
      'cookie_httponly' => true,
      'cookie_samesite' => 'Lax',
      'use_strict_mode' => true,
    ]);
  }
}
