Skip to content

Instantly share code, notes, and snippets.

@bumbummen99
Created January 12, 2023 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumbummen99/64375f2ccc921d6e736deb6772741a46 to your computer and use it in GitHub Desktop.
Save bumbummen99/64375f2ccc921d6e736deb6772741a46 to your computer and use it in GitHub Desktop.
Bash helper to run Composer with a specific PHP version using Docker.
#!/usr/bin/env bash
# Bash helper to run Composer with a specific PHP version using Docker.
# Source this file in your profile/bashrc or add it to bash_aliases.
#
# Author: Patrick Henninger <privat@skyraptor.eu>
# License: GPLv3
# Examples:
# dcomposer
#
# dcomposer 7.4
#
# dcomposer 8.1 require vendor/package
function dcomposer() {
PHP="$(echo ${1:-'8.1'} | tr -d '.')" # Get the PHP version or use default (8.1)
ARGS="${@:2}" # Get all arguments except first
CMD="${ARGS:-install}" # Use arguments to build the command or use default (install)
echo "Running Composer using PHP-$PHP running command \"composer $CMD\" --ignore-platform-reqs."
docker run --rm \
-u "$(id -u):$(id -g)" \
-v "$(pwd):/var/www/html" \
-w /var/www/html \
laravelsail/php$PHP-composer:latest \
composer $CMD --ignore-platform-reqs
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment