From a16ad85b7a2b5db6227955e0c91b6d534cffff05 Mon Sep 17 00:00:00 2001 From: safinsingh Date: Thu, 12 Nov 2020 21:29:28 -0800 Subject: [PATCH] feat: refresh repository --- README.md | 145 ++++++++++++++++++---------------------- bug-report.sh | 5 +- changelog.md | 9 ++- php-version.sh | 175 ------------------------------------------------- php_version.sh | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 247 insertions(+), 259 deletions(-) delete mode 100755 php-version.sh create mode 100644 php_version.sh diff --git a/README.md b/README.md index 855b85e..7bad90d 100644 --- a/README.md +++ b/README.md @@ -4,54 +4,48 @@ ![](https://i.cloudup.com/Rl7FXze6ra.png) - ## This _IS_ for you if -- You are not satisifed with heavy handed *AMP or PPA-based installers. -- You [use multiple][homebrew-php] [versions][php-build] of PHP on Linux or Mac. -- You download [pre-compiled PHP binaries for Windows][windows-bin] (**NOTE**: this is a [bash] script so you'll need [WSL]). -- You want to run your automated tests against multiple PHP versions. -- You are a developer that works on a variety of PHP projects each requiring different versions of PHP. -- You want to work on the latest PHP, but expect to support prior work that was done on older PHP versions. - +- You are not satisifed with heavy handed \*AMP or PPA-based installers. +- You [use multiple][homebrew-php] [versions][php-build] of PHP on Linux or Mac. +- You download [pre-compiled PHP binaries for Windows][windows-bin] (**NOTE**: this is a [bash] script so you'll need [WSL]). +- You want to run your automated tests against multiple PHP versions. +- You are a developer that works on a variety of PHP projects each requiring different versions of PHP. +- You want to work on the latest PHP, but expect to support prior work that was done on older PHP versions. ## This is _NOT_ for you if -- You are content with heavy handed *AMP installers. -- You are provisioning a production server so you only need a single PHP install. -- You **NEVER** work on more than one PHP project at a time. -- You don't plan on supporting prior work that was done on other PHP versions. - +- You are content with heavy handed \*AMP installers. +- You are provisioning a production server so you only need a single PHP install. +- You **NEVER** work on more than one PHP project at a time. +- You don't plan on supporting prior work that was done on other PHP versions. ## Rationale **php-version** attempts to stick to the classic UNIX notion that tools should do one thing well. -> While there are [smart](https://github.com/c9s/phpbrew) [alternative](https://github.com/CHH/phpenv) -> [tools](https://sourceforge.net/p/phpfarm/wiki/Home/) that attempt to [solve](https://github.com/convissor/php_version_solution) -> this problem, [none](https://www.gnu.org/s/stow/) of the tools I've found were simple enough for me. - +> While there are [smart](https://github.com/c9s/phpbrew) [alternative](https://github.com/CHH/phpenv) +> [tools](https://sourceforge.net/p/phpfarm/wiki/Home/) that attempt to [solve](https://github.com/convissor/php_version_solution) +> this problem, [none](https://www.gnu.org/s/stow/) of the tools I've found were simple enough for me. ## Features -- [Homebrew installed PHP versions][homebrew-php] are picked up automatically. -- PHP versions installed [into `~/.phps`][build-php-vers] are picked up automatically. -- PHP versions listed in the `$PHP_VERSIONS` shell variable are picked up automatically. -- **snap versioning**: Use a partial version number (i.e. `php-version 5`) to automatically use the latest 5.x version. -- **per version `php.ini`**: we `export PHPRC` if a version-specific `php.ini` exists. -- **configurable**: `php-version --help` for details. -- **[bash], [zsh], and [fish]** shells actively supported; though care has been taken such that other shells are _likely_ to work as well. -- **tiny**: less than 200 LOC; a single function sourced via your shell's initialization file. - +- [Homebrew installed PHP versions][homebrew-php] are picked up automatically. +- PHP versions installed [into `~/.phps`][build-php-vers] are picked up automatically. +- PHP versions listed in the `$PHP_VERSIONS` shell variable are picked up automatically. +- **snap versioning**: Use a partial version number (i.e. `php-version 5`) to automatically use the latest 5.x version. +- **per version `php.ini`**: we `export PHPRC` if a version-specific `php.ini` exists. +- **configurable**: `php-version --help` for details. +- **[bash], [zsh], and [fish]** shells actively supported; though care has been taken such that other shells are _likely_ to work as well. +- **tiny**: less than 200 LOC; a single function sourced via your shell's initialization file. ## Non-Features -- no [shims][], sub-shells, symlinks or `cd` [hooks][]. -- we won't leave files and symlinks all over the place. -- does not attempt to manage Apache, MySQL, etc. -- does not attempt to compile, build, or install PHP. -- does not attempt to support OS package manager installed (i.e. ppa, etc.) PHP versions. - +- no [shims][], sub-shells, symlinks or `cd` [hooks][]. +- we won't leave files and symlinks all over the place. +- does not attempt to manage Apache, MySQL, etc. +- does not attempt to compile, build, or install PHP. +- does not attempt to support OS package manager installed (i.e. ppa, etc.) PHP versions. ## Usage Examples @@ -59,7 +53,7 @@ % php-version -### List installed and active (*) PHP version(s) +### List installed and active (\*) PHP version(s) % php-version 5.3.9 @@ -69,7 +63,6 @@ 5.4.0 * 5.4.8 - ## Install **[homebrew](https://brew.sh/)** (recommended for OSX users) @@ -85,7 +78,6 @@ [Alternative (i.e. non-Homebrew) installation methods][opt-install] are documented on the wiki. - ## Setup > Add one of the following to your shell's initialization file: @@ -108,9 +100,9 @@ Type `php-version --help` for more configuration options such as how to add extr ## Deactivate / Uninstall -1. Remove [setup](https://github.com/wilmoore/php-version#setup) configuration. +1. Remove [setup](https://github.com/wilmoore/php-version#setup) configuration. -2. Enter one of the following commands listed below to remove associated files. +2. Enter one of the following commands listed below to remove associated files. # Homebrew (recommended) % brew remove --force php-version @@ -118,68 +110,61 @@ Type `php-version --help` for more configuration options such as how to add extr # non-Homebrew % rm -rf $HOME/local/php-version - ## Having Issues? -1. Copy the bug report output to your clipboard (`pbcopy` works on Mac OSX; use your OS equivalent) +1. Copy the bug report output to your clipboard (`pbcopy` works on Mac OSX; use your OS equivalent) % cd /tmp % git clone https://github.com/wilmoore/php-version.git % source php-version/bug-report.sh | pbcopy -2. File an [issue](https://github.com/wilmoore/php-version/issues?state=open). - +2. File an [issue](https://github.com/wilmoore/php-version/issues?state=open). ## More Info -- [Building PHP Versions][build-php-vers] -- [Exploring PHP][exploring] -- [Troubleshooting][trouble] - +- [Building PHP Versions][build-php-vers] +- [Exploring PHP][exploring] +- [Troubleshooting][trouble] ## Contributors -> https://github.com/wilmoore/php-version/graphs/contributors +> https://github.com/wilmoore/php-version/graphs/contributors ## Alternatives -- [brew-php-switcher](https://github.com/philcook/brew-php-switcher) -- [phpbrew](https://github.com/c9s/phpbrew) -- [phpenv](https://github.com/CHH/phpenv) -- [phpenv](https://github.com/humanshell/phpenv) -- [php_version_solution](https://github.com/convissor/php_version_solution) -- [phpfarm](https://sourceforge.net/p/phpfarm/wiki/Home/) -- [GNU Stow](https://www.gnu.org/s/stow/) -- [phpswitch](https://github.com/jubianchi/phpswitch) - +- [brew-php-switcher](https://github.com/philcook/brew-php-switcher) +- [phpbrew](https://github.com/c9s/phpbrew) +- [phpenv](https://github.com/CHH/phpenv) +- [phpenv](https://github.com/humanshell/phpenv) +- [php_version_solution](https://github.com/convissor/php_version_solution) +- [phpfarm](https://sourceforge.net/p/phpfarm/wiki/Home/) +- [GNU Stow](https://www.gnu.org/s/stow/) +- [phpswitch](https://github.com/jubianchi/phpswitch) ## Inspiration -- [n](https://github.com/visionmedia/n) -- [nvm](https://github.com/creationix/nvm) -- [rbenv](https://github.com/sstephenson/rbenv) -- [rbfu](https://github.com/hmans/rbfu) -- [ry](https://github.com/jayferd/ry) - +- [n](https://github.com/visionmedia/n) +- [nvm](https://github.com/creationix/nvm) +- [rbenv](https://github.com/sstephenson/rbenv) +- [rbfu](https://github.com/hmans/rbfu) +- [ry](https://github.com/jayferd/ry) ## LICENSE - MIT - - - -[bash]: https://www.gnu.org/software/bash/ -[build-php-vers]: https://github.com/wilmoore/php-version/wiki/Building-PHP-Versions -[exploring]: https://github.com/wilmoore/php-version/wiki/Exploring-PHP -[fish]: https://fishshell.com/ -[homebrew-php]: https://github.com/josegonzalez/homebrew-php -[hooks]: https://rvm.io/workflow/hooks -[manual-build]: https://github.com/wilmoore/php-version#compilation-recommendations -[opt-install]: https://github.com/wilmoore/php-version/wiki/Installing -[php-build]: https://github.com/CHH/php-build -[shims]: https://github.com/sstephenson/rbenv#understanding-shims -[trouble]: https://github.com/wilmoore/php-version/wiki/Troubleshooting -[windows-bin]: http://windows.php.net/download -[windows-port]: https://github.com/wilmoore/php-version/issues/2 -[WSL]: https://docs.microsoft.com/en-us/windows/wsl/install-win10 -[zsh]: https://www.zsh.org/ +MIT + +[bash]: https://www.gnu.org/software/bash/ +[build-php-vers]: https://github.com/wilmoore/php-version/wiki/Building-PHP-Versions +[exploring]: https://github.com/wilmoore/php-version/wiki/Exploring-PHP +[fish]: https://fishshell.com/ +[homebrew-php]: https://github.com/josegonzalez/homebrew-php +[hooks]: https://rvm.io/workflow/hooks +[manual-build]: https://github.com/wilmoore/php-version#compilation-recommendations +[opt-install]: https://github.com/wilmoore/php-version/wiki/Installing +[php-build]: https://github.com/CHH/php-build +[shims]: https://github.com/sstephenson/rbenv#understanding-shims +[trouble]: https://github.com/wilmoore/php-version/wiki/Troubleshooting +[windows-bin]: http://windows.php.net/download +[windows-port]: https://github.com/wilmoore/php-version/issues/2 +[wsl]: https://docs.microsoft.com/en-us/windows/wsl/install-win10 +[zsh]: https://www.zsh.org/ diff --git a/bug-report.sh b/bug-report.sh index c853b5c..99bbddb 100755 --- a/bug-report.sh +++ b/bug-report.sh @@ -11,7 +11,7 @@ cat <<-EOF ## Script TYPE: $(command -v php-version 2>/dev/null || echo 'NOT FOUND') - VERSION: $(php-version --version 2>/dev/null || echo 'NOT FOUND') + VERSION: $(php-version --version 2>/dev/null || echo 'NOT FOUND') ## Environment @@ -22,7 +22,7 @@ cat <<-EOF ## Homebrew - VERSION: $(test -n `command -v brew` && brew --version) + VERSION: $(test -n $(command -v brew) && brew --version) PATH: $(command -v brew) PHPS: $(find $(brew --cellar) -maxdepth 1 -type d | grep -E 'php[0-9]+$') @@ -33,5 +33,4 @@ cat <<-EOF ## INI $(php --ini | sed 's/^/ /') - EOF diff --git a/changelog.md b/changelog.md index 0865a1c..0b44fb6 100755 --- a/changelog.md +++ b/changelog.md @@ -1,14 +1,21 @@ # Change Log + All notable changes to this project will be documented in this file (keepachangelog.com). ## 0.13.0 - 2019-03-11 + ### Added + - Added a changelog. - Added a note for windows users to get WSL (#74) - Added support for v7 PHP () + ### Changed + - Updated installation instructions to point to this tap: `wilmoore/formulae` (#71, #67) ## 0.12.1 - 2015-08-05 + ### Changed -- Replace ~ with $HOME in PHP_VERSIONS example. + +- Replace ~ with \$HOME in PHP_VERSIONS example. diff --git a/php-version.sh b/php-version.sh deleted file mode 100755 index d6b6467..0000000 --- a/php-version.sh +++ /dev/null @@ -1,175 +0,0 @@ -################################################################################ -# php-version: function allowing one to switch between PHP versions -################################################################################ - -function php-version { - local PROGRAM_APPNAME='php-version' - local PROGRAM_VERSION=0.13.0 - local PROGRAM_DISPLAY_VERSION="$PROGRAM_APPNAME v$PROGRAM_VERSION" - - # colors - COLOR_NORMAL=$(tput sgr0) - COLOR_REVERSE=$(tput smso) - - # target version - local _TARGET_VERSION=$1 - - # PHP installation paths - local _PHP_VERSIONS="" - - # add ~/.phps if it exists (default) - if [[ -d $HOME/.phps ]]; then - export _PHP_VERSIONS="$_PHP_VERSIONS $HOME/.phps" - fi - - # add default Homebrew directories if brew is installed - if [[ -n $(command -v brew) ]]; then - export _PHP_VERSIONS="$_PHP_VERSIONS $(echo $(find $(brew --cellar) -maxdepth 1 -type d | grep -E 'php$|php@[0-9\.]*$'))" - fi - - # add extra directories if configured - if [[ -n $PHP_VERSIONS ]]; then - export _PHP_VERSIONS="$_PHP_VERSIONS $PHP_VERSIONS" - fi - - # export the space-separated string as array - _PHP_REPOSITORIES=() - for _PHP_VERSION in $(echo $_PHP_VERSIONS | tr " " "\n"); do - _PHP_REPOSITORIES=("${_PHP_REPOSITORIES[@]}" $_PHP_VERSION) - done - - # unset the string - _PHP_VERSIONS= - - # argument parsing - case "$1" in - - -h|--help|-u|--usage) - - echo $PROGRAM_DISPLAY_VERSION - - cat <<-USAGE - - Usage: - $PROGRAM_APPNAME --help Show this message - $PROGRAM_APPNAME --version Print the version - $PROGRAM_APPNAME Modify PATH to use - $PROGRAM_APPNAME Show all available versions and denote the currently activated version - - Example: - $PROGRAM_APPNAME 5 Activate the latest available 5.x version - $PROGRAM_APPNAME 5.5 Activate the latest available 5.5.x version - $PROGRAM_APPNAME 5.5.13 Activate version 5.5.13 specifically - - Configuration Options: - https://github.com/wilmoore/php-version#setup - - Uninstall: - https://github.com/wilmoore/php-version#deactivate--uninstall - - USAGE - - return 0 - ;; - - -v|--version) - - echo $PROGRAM_DISPLAY_VERSION - - return 0 - ;; - - -*) - - printf "\e[0;31m%s: %s: unrecognized option\e[0m\n\n" $0 $1 >&2 - php-version --help >&2 - - return 1 - ;; - - "") - - # bail-out if _PHP_REPOSITORIES is an empty array - if [ ${#_PHP_REPOSITORIES[@]} -eq 0 ]; then - echo 'Sorry, but you do not seem to have any PHP versions installed.' >&2 - echo 'See https://github.com/wilmoore/php-version#install for assistance.' >&2 - return 1 - fi - - # Loop through all repositories and get every single php-version - _PHP_VERSIONS=() - for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do - for _dir in $(find -H $(echo $_PHP_REPOSITORY) -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do - _PHP_VERSIONS=("${_PHP_VERSIONS[@]}" "$($_dir/bin/php-config --version 2>/dev/null)") - done - done - - _PHP_VERSIONS=$(IFS=$'\n'; echo "${_PHP_VERSIONS[*]}" | sort -r -t . -k 1,1n -k 2,2n -k 3,3n) - - for version in $(echo $_PHP_VERSIONS | tr " " "\n"); do - local selected=" " - local color=$COLOR_NORMAL - - if [[ "$version" == "$(php-config --version 2>/dev/null)" ]]; then - local selected="*" - local color=$COLOR_REVERSE - fi - - printf "${color}%s %s${COLOR_NORMAL}\n" "$selected" "$version" - done - - return 0 - ;; - - esac - - # locate selected PHP version - for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do - if [[ -d "$_PHP_REPOSITORY/$_TARGET_VERSION" && -z $_PHP_ROOT ]]; then - local _PHP_ROOT=$_PHP_REPOSITORY/$_TARGET_VERSION - break; - fi - done - - # try a fuzzy match since we were unable to find a PHP matching given version - if [[ -z $_PHP_ROOT ]]; then - _TARGET_VERSION_FUZZY=() - - for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do - for _dir in $(find -H $_PHP_REPOSITORY -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do - _TARGET_VERSION_FUZZY=("${_TARGET_VERSION_FUZZY[@]}" "$($_dir/bin/php-config --version 2>/dev/null)") - done - done - - _TARGET_VERSION_FUZZY=$(IFS=$'\n'; echo "${_TARGET_VERSION_FUZZY[*]}" | sort -r -t . -k 1,1n -k 2,2n -k 3,3n | grep -E "^$_TARGET_VERSION" 2>/dev/null | tail -1) - - for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do - for _dir in $(find -H $_PHP_REPOSITORY -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do - _PHP_VERSION="$($_dir/bin/php-config --version 2>/dev/null)" - if [[ -n "$_TARGET_VERSION_FUZZY" && "$_PHP_VERSION" == "$_TARGET_VERSION_FUZZY" ]]; then - local _PHP_ROOT=$_dir - break; - fi - done - done - fi - - # bail-out if we were unable to find a PHP matching given version - if [[ -z $_PHP_ROOT ]]; then - echo "Sorry, but $PROGRAM_APPNAME was unable to find version '$1' under '${_PHP_PATHS[@]}'." >&2 - return 1 - fi - - # export current paths - export PHPRC="" - [[ -f $_PHP_ROOT/etc/php.ini ]] && export PHPRC=$_PHP_ROOT/etc/php.ini - [[ -d $_PHP_ROOT/bin ]] && export PATH="$_PHP_ROOT/bin:$PATH" - [[ -d $_PHP_ROOT/sbin ]] && export PATH="$_PHP_ROOT/sbin:$PATH" - - # use configured manpath if it exists, otherwise, use `$_PHP_ROOT/share/man` - local _MANPATH=$(php-config --man-dir) - [[ -z $_MANPATH ]] && _MANPATH=$_PHP_ROOT/share/man - [[ -d $_MANPATH ]] && export MANPATH="$_MANPATH:$MANPATH" - - hash -r -} diff --git a/php_version.sh b/php_version.sh new file mode 100644 index 0000000..70a2840 --- /dev/null +++ b/php_version.sh @@ -0,0 +1,172 @@ +#!/usr/bin/env bash + +# _ _ +# _ __ | |__ _ __ __ _____ _ __ ___(_) ___ _ __ +# | '_ \| '_ \| '_ \ \ \ / / _ \ '__/ __| |/ _ \| '_ \ +# | |_) | | | | |_) | \ V / __/ | \__ \ | (_) | | | | +# | .__/|_| |_| .__/___\_/ \___|_| |___/_|\___/|_| |_| +# |_| |_| |_____| +# +# quickly and conveniently switch between PHP versions + +php_version() { + PROGRAM_APPNAME='php_version' + PROGRAM_VERSION=0.13.0 + PROGRAM_DISPLAY_VERSION="$PROGRAM_APPNAME v$PROGRAM_VERSION" + + # colors + COLOR_NORMAL=$(tput sgr0) + COLOR_REVERSE=$(tput smso) + + # target version + _TARGET_VERSION=$1 + + # PHP installation paths + _PHP_VERSIONS="" + + # add ~/.phps if it exists (default) + if [ -d "$HOME"/.phps ]; then + export _PHP_VERSIONS="$_PHP_VERSIONS $HOME/.phps" + fi + + # add default Homebrew directories if brew is installed + if [ -n "$(command -v brew)" ]; then + _PHP_VERSIONS="$_PHP_VERSIONS $(find "$(brew --cellar)" -maxdepth 1 -type d | grep -E 'php$|php@[0-9\.]*$')" + export _PHP_VERSIONS + fi + + # add extra directories if configured + if [ -n "$PHP_VERSIONS" ]; then + export _PHP_VERSIONS="$_PHP_VERSIONS $PHP_VERSIONS" + fi + + # export the space-separated string as array + _PHP_REPOSITORIES=() + for _PHP_VERSION in $(echo "$_PHP_VERSIONS" | tr " " "\n"); do + _PHP_REPOSITORIES=("${_PHP_REPOSITORIES[@]}" "$_PHP_VERSION") + done + + # unset the string + _PHP_VERSIONS= + + # argument parsing + case "$1" in + + -h | --help | -u | --usage) + echo "$PROGRAM_DISPLAY_VERSION" + cat <<-USAGE + Usage: + $PROGRAM_APPNAME --help Show this message + $PROGRAM_APPNAME --version Print the version + $PROGRAM_APPNAME Modify PATH to use + $PROGRAM_APPNAME Show all available versions and denote the currently activated version + Example: + $PROGRAM_APPNAME 5 Activate the latest available 5.x version + $PROGRAM_APPNAME 5.5 Activate the latest available 5.5.x version + $PROGRAM_APPNAME 5.5.13 Activate version 5.5.13 specifically + Configuration Options: + https://github.com/wilmoore/php-version#setup + Uninstall: + https://github.com/wilmoore/php-version#deactivate--uninstall + USAGE + return 0 + ;; + -v | --version) + echo "$PROGRAM_DISPLAY_VERSION" + return 0 + ;; + -*) + printf "\e[0;31m%s: %s: unrecognized option\e[0m\n\n" "$0" "$1" >&2 + php-version --help >&2 + return 1 + ;; + "") + # bail-out if _PHP_REPOSITORIES is an empty array + if [ ${#_PHP_REPOSITORIES[@]} -eq 0 ]; then + echo 'Sorry, but you do not seem to have any PHP versions installed.' >&2 + echo 'See https://github.com/wilmoore/php-version#install for assistance.' >&2 + return 1 + fi + + # Loop through all repositories and get every single php-version + _PHP_VERSIONS=() + for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do + for _dir in $(find -H $_PHP_REPOSITORY -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do + _PHP_VERSIONS=("${_PHP_VERSIONS[@]}" "$("$_dir"/bin/php-config --version 2>/dev/null)") + done + done + + _PHP_VERSIONS=$( + IFS=$'\n' + echo "${_PHP_VERSIONS[*]}" | sort -r -t . -k 1,1n -k 2,2n -k 3,3n + ) + + for version in $(echo "$_PHP_VERSIONS" | tr " " "\n"); do + selected=" " + color=$COLOR_NORMAL + + if [ "$version" == "$(php-config --version 2>/dev/null)" ]; then + selected="*" + color=$COLOR_REVERSE + fi + + printf "${color}%s %s${COLOR_NORMAL}\n" "$selected" "$version" + done + + return 0 + ;; + esac + + # locate selected PHP version + for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do + if [ -d "$_PHP_REPOSITORY/$_TARGET_VERSION" ] && [ -z "$_PHP_ROOT" ]; then + _PHP_ROOT=$_PHP_REPOSITORY/$_TARGET_VERSION + break + fi + done + + # try a fuzzy match since we were unable to find a PHP matching given version + if [ -z "$_PHP_ROOT" ]; then + _TARGET_VERSION_FUZZY=() + + for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do + for _dir in $(find -H $_PHP_REPOSITORY -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do + _TARGET_VERSION_FUZZY=("${_TARGET_VERSION_FUZZY[@]}" "$("$_dir"/bin/php-config --version 2>/dev/null)") + done + done + + _TARGET_VERSION_FUZZY=$( + IFS=$'\n' + echo "${_TARGET_VERSION_FUZZY[*]}" | sort -r -t . -k 1,1n -k 2,2n -k 3,3n | grep -E "^$_TARGET_VERSION" 2>/dev/null | tail -1 + ) + + for _PHP_REPOSITORY in "${_PHP_REPOSITORIES[@]}"; do + for _dir in $(find -H $_PHP_REPOSITORY -maxdepth 1 -mindepth 1 -type d 2>/dev/null); do + _PHP_VERSION="$($_dir/bin/php-config --version 2>/dev/null)" + if [ -n "$_TARGET_VERSION_FUZZY" ] && [ "$_PHP_VERSION" == "$_TARGET_VERSION_FUZZY" ]; then + _PHP_ROOT=$_dir + break + fi + done + done + fi + + # bail-out if we were unable to find a PHP matching given version + if [ -z "$_PHP_ROOT" ]; then + echo "Sorry, but $PROGRAM_APPNAME was unable to find version '$1' under '" "${_PHP_PATHS[@]}" "'." >&2 + return 1 + fi + + # export current paths + export PHPRC="" + [ -f "$_PHP_ROOT"/etc/php.ini ] && export PHPRC=$_PHP_ROOT/etc/php.ini + [ -d "$_PHP_ROOT"/bin ] && export PATH="$_PHP_ROOT/bin:$PATH" + [ -d "$_PHP_ROOT"/sbin ] && export PATH="$_PHP_ROOT/sbin:$PATH" + + # use configured manpath if it exists, otherwise, use `$_PHP_ROOT/share/man` + _MANPATH=$(php-config --man-dir) + [ -z "$_MANPATH" ] && _MANPATH=$_PHP_ROOT/share/man + [ -d "$_MANPATH" ] && export MANPATH="$_MANPATH:$MANPATH" + + hash -r +}