Created
January 12, 2023 13:18
-
-
Save bumbummen99/64375f2ccc921d6e736deb6772741a46 to your computer and use it in GitHub Desktop.
Bash helper to run Composer with a specific PHP version using Docker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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