#!/bin/bash
# PHP 8.3 wrapper using podman
# Auto-detects artisan serve and adds port forwarding

# Check if this is an artisan serve command
if [[ "$*" == *"artisan serve"* ]]; then
    # Extract the --port argument if provided, default to 8000
    PORT="8000"
    for arg in "$@"; do
        if [[ "$arg" =~ ^--port=([0-9]+)$ ]]; then
            PORT="${BASH_REMATCH[1]}"
            break
        fi
    done
    podman run --rm -p "$PORT":"$PORT" -v "$PWD":/app:z -w /app php:8.3-cli php "$@"
else
    podman run --rm -v "$PWD":/app:z -w /app php:8.3-cli php "$@"
fi
