#!/usr/bin/env bash
set -euo pipefail

ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
PHP_BIN="${PHP_BIN:-$ROOT_DIR/.local/php/usr/bin/php8.3}"
PHP_INI="${PHP_INI:-$ROOT_DIR/.local/php-dev.ini}"
PHP_LIB_DIR="$ROOT_DIR/.local/php/usr/lib/x86_64-linux-gnu"

export LD_LIBRARY_PATH="${LD_LIBRARY_PATH:-$PHP_LIB_DIR}"
export APP_DB_DRIVER="${APP_DB_DRIVER:-mysql}"
export APP_ENV="${APP_ENV:-dev}"
export DEV_AUTH_EMAIL="${DEV_AUTH_EMAIL:-admin@test.local}"
export DEV_AUTH_NAME="${DEV_AUTH_NAME:-Test Admin}"

exec "$PHP_BIN" -c "$PHP_INI" -S "${HOST:-127.0.0.1}:${PORT:-8080}" -t "$ROOT_DIR"
