#!/usr/bin/env bash

# Set environment variables for dev
export APP_PORT=${APP_PORT:-80}

COMPOSE="docker-compose"

# if any arguments pass to docker compose otherwise run docker-compose ps
if [ $# -gt 0 ];then
    # If "composer" is used, pass-thru to "composer"
    # inside a new container
    if [ "$1" == "composer" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            app \
            composer "$@"

    # If "test" is used, run unit tests,
    # pass-thru any extra arguments to php-unit
    elif [ "$1" == "test" ]; then
        shift 1
        $COMPOSE run --rm \
            -w /var/www/html \
            app \
            ./vendor/bin/phpunit "$@"

    # Else, pass-thru args to docker-compose
    else
        $COMPOSE "$@"
    fi
else
    $COMPOSE ps
fi