mirror of
https://github.com/shivammathur/setup-php.git
synced 2024-11-26 05:23:03 +07:00
Fix to not use system PHP on macOS
Refactor add_php in darwin.sh
This commit is contained in:
parent
ed61605069
commit
d5790807c8
@ -134,31 +134,43 @@ update_dependencies() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to get PHP version if it is already installed using Homebrew.
|
||||||
|
get_brewed_php() {
|
||||||
|
php_cellar="$brew_prefix"/Cellar/php
|
||||||
|
if [ -d "$php_cellar" ] && ! [[ "$(find "$php_cellar" -maxdepth 1 -name "$version*" | wc -l 2>/dev/null)" -eq 0 ]]; then
|
||||||
|
php-config --version 2>/dev/null | cut -c 1-3
|
||||||
|
else
|
||||||
|
echo 'false';
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Function to setup PHP 5.6 and newer using Homebrew.
|
# Function to setup PHP 5.6 and newer using Homebrew.
|
||||||
add_php() {
|
add_php() {
|
||||||
action=$1
|
action=$1
|
||||||
|
existing_version=$2
|
||||||
|
php_formula=shivammathur/php/php@"$version"
|
||||||
add_brew_tap shivammathur/homebrew-php
|
add_brew_tap shivammathur/homebrew-php
|
||||||
update_dependencies
|
update_dependencies
|
||||||
if ! [[ "$(find "$(brew --cellar)"/php/ -maxdepth 1 -name "$version*" | wc -l 2>/dev/null)" -eq 0 ]] && [ "$action" != "upgrade" ]; then
|
if [ "$existing_version" != "false" ]; then
|
||||||
brew unlink shivammathur/php/php@"$version"
|
([ "$action" = "upgrade" ] && brew upgrade -f "$php_formula") || brew unlink "$php_formula"
|
||||||
else
|
else
|
||||||
brew upgrade -f "shivammathur/php/php@$version" 2>/dev/null || brew install -f "shivammathur/php/php@$version"
|
brew install -f "$php_formula"
|
||||||
fi
|
fi
|
||||||
brew link --force --overwrite shivammathur/php/php@"$version"
|
brew link --force --overwrite "$php_formula"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Function to Setup PHP
|
# Function to Setup PHP
|
||||||
setup_php() {
|
setup_php() {
|
||||||
step_log "Setup PHP"
|
step_log "Setup PHP"
|
||||||
existing_version=$(php-config --version 2>/dev/null | cut -c 1-3)
|
existing_version=$(get_brewed_php)
|
||||||
if [[ "$version" =~ ${old_versions:?} ]]; then
|
if [[ "$version" =~ ${old_versions:?} ]]; then
|
||||||
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
|
run_script "php5-darwin" "${version/./}" >/dev/null 2>&1
|
||||||
status="Installed"
|
status="Installed"
|
||||||
elif [ "$existing_version" != "$version" ]; then
|
elif [ "$existing_version" != "$version" ]; then
|
||||||
add_php "install" >/dev/null 2>&1
|
add_php "install" "$existing_version" >/dev/null 2>&1
|
||||||
status="Installed"
|
status="Installed"
|
||||||
elif [ "$existing_version" = "$version" ] && [ "${update:?}" = "true" ]; then
|
elif [ "$existing_version" = "$version" ] && [ "${update:?}" = "true" ]; then
|
||||||
add_php "upgrade" >/dev/null 2>&1
|
add_php "upgrade" "$existing_version" >/dev/null 2>&1
|
||||||
status="Updated to"
|
status="Updated to"
|
||||||
else
|
else
|
||||||
status="Found"
|
status="Found"
|
||||||
|
Loading…
Reference in New Issue
Block a user