message: Fix extension setup using PECL on Linux and macOS
diff: @@ -144,14 +144,18 @@ add_extension() {
  # Function to get the PECL version of an extension.
  get_pecl_version() {
  local extension=$1
  - stability="$(echo "$2" | grep -m 1 -Eio "(stable|alpha|beta|rc|snapshot|preview)")"
  + states=("stable" "rc" "preview" "beta" "alpha" "snapshot")
  + stability="$(echo "$2" | grep -m 1 -Eio "($(IFS='|' ; echo "${states[*]}"))")"
  + IFS=' ' read -r -a states <<< "$(echo "${states[@]}" | grep -Eo "$stability.*")"
  major_version=${3:-'[0-9]+'}
  pecl_rest='https://pecl.php.net/rest/r/'
  response=$(get -s -n "" "$pecl_rest$extension"/allreleases.xml)
  - pecl_version=$(echo "$response" | grep -m 1 -Eio "($major_version\.[0-9]+\.[0-9]+${stability}[0-9]+<)" | cut -d '<' -f 1)
  - if [ ! "$pecl_version" ]; then
  - pecl_version=$(echo "$response" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+)<" | cut -d '<' -f 1)
  - fi
  + for state in "${states[@]}"; do
  + pecl_version=$(echo "$response" | grep -m 1 -Eio "($major_version\.[0-9]+\.[0-9]+${state}[0-9]+<)" | cut -d '<' -f 1)
  + [ -z "$pecl_version" ] && pecl_version=$(echo "$response" | grep -m 1 -Eio "v>(.*)<\/v>.*$state<" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+.*)<" | cut -d '<' -f 1)
  + [ -n "$pecl_version" ] && break;
  + done
  + [ -z "$pecl_version" ] && pecl_version=$(echo "$response" | grep -m 1 -Eo "($major_version\.[0-9]+\.[0-9]+)<" | cut -d '<' -f 1)
  echo "$pecl_version"
  }
  @@ -185,8 +189,9 @@ add_pecl_extension() {
  add_log "${tick:?}" "$extension" "Enabled"
  else
  disable_extension_helper "$extension" >/dev/null 2>&1
  - pecl_install "$extension-$pecl_version"
  - add_extension_log "$extension-$pecl_version" "Installed and enabled"
  + [ -n "$pecl_version" ] && pecl_version="-$pecl_version"
  + pecl_install "$extension$pecl_version" || add_extension "$extension" "$(get_extension_prefix "$extension")"
  + add_extension_log "$extension-$(php -r "echo phpversion('$extension');")" "Installed and enabled"
  fi
  }
  @@ -198,3 +203,8 @@ add_unstable_extension() {
  pecl_version=$(get_pecl_version "$extension" "$stability")
  add_pecl_extension "$extension" "$pecl_version" "$prefix"
  }
  +
  +# Function to get extension prefix
  +get_extension_prefix() {
  + echo "$1" | grep -Eq "xdebug([2-3])?$|opcache|ioncube|eaccelerator" && echo zend_extension || echo extension
  +}
  