<?php
declare(strict_types=1);

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

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

function start_app_session(): void {
  $name = cfg()['app']['session_name'] ?? 'app_sess';
  if (session_status() !== PHP_SESSION_ACTIVE) {
    session_name($name);
    session_start([
      'cookie_httponly' => true,
      'cookie_samesite' => 'Lax',
      'use_strict_mode' => true,
    ]);
  }
}
