Skip to content

Commit 8a1339a

Browse files
authored
Merge pull request #12 from Thavarshan/fix/github-issues-v1.5.0
Fix/GitHub issues v1.5.0
2 parents bbb5958 + 9d395b8 commit 8a1339a

File tree

2 files changed

+89
-11
lines changed

2 files changed

+89
-11
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
# Release Notes
22

3+
## [v1.5.0](https://github.com/Thavarshan/phpvm/compare/v1.4.1...v1.5.0) - 2025-08-15
4+
5+
### Added
6+
7+
- **Added comprehensive version command support:** Implemented `phpvm version`, `phpvm --version`, and `phpvm -v` commands with detailed information including author, repository link, and usage hints.
8+
- **Added intelligent system PHP detection:** Enhanced system PHP switching to properly detect and use Homebrew's main `php` formula as the system default on modern macOS.
9+
- **Added post-install validation:** Added checks for PHP binary availability after installation with helpful warnings if binaries are missing.
10+
11+
### Changed
12+
13+
- **Improved shebang for WSL compatibility:** Changed from `#!/bin/sh` to `#!/bin/bash` for better compatibility with WSL and Linux distributions.
14+
- **Enhanced Homebrew link failure detection:** Improved detection and handling of "already linked" warnings from Homebrew with proper error reporting and user guidance.
15+
- **Updated system PHP messaging:** Changed misleading "macOS built-in PHP" references to accurate "Homebrew default PHP" messaging that reflects modern macOS reality.
16+
- **Improved PHP version detection on Linux:** Enhanced `dpkg-query` usage for more reliable PHP version listing on Debian/Ubuntu systems.
17+
- **Enhanced unlinking logic:** Replaced problematic wildcard unlinking with proper iteration through installed PHP formulas.
18+
19+
### Fixed
20+
21+
- **Fixed false success reporting on Homebrew link failures:** Script now properly detects when `brew link` fails due to "already linked" status and returns error instead of false success.
22+
- **Fixed WSL script execution issues:** Resolved problem where phpvm would exit silently without output on WSL/Ubuntu systems due to shell compatibility issues.
23+
- **Fixed system PHP switching on macOS:** System switching now correctly links to Homebrew's main PHP installation instead of looking for non-existent `/usr/bin/php`.
24+
- **Fixed PHP version listing on Linux:** Improved reliability of `phpvm list` command showing installed PHP versions on apt-based systems.
25+
- **Fixed error handling for missing PHP binaries:** Added proper error handling when PHP commands are not available, preventing script crashes.
26+
327
## [v1.4.1](https://github.com/Thavarshan/phpvm/compare/v1.4.0...v1.4.1) - 2025-07-13
428

529
### Fixed

phpvm.sh

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
#!/bin/sh
1+
#!/bin/bash
22

33
# phpvm - A PHP Version Manager for macOS and Linux
44
# Author: Jerome Thayananthajothy ([email protected])
5+
# Version: 1.5.0
6+
7+
PHPVM_VERSION="1.5.0"
58

69
# Define a debug mode for testing
710
if [ "${BATS_TEST_FILENAME:-}" != "" ]; then
@@ -134,6 +137,10 @@ install_php() {
134137
phpvm_err "Failed to install PHP $version. Package php$version may not exist."
135138
return 1
136139
fi
140+
# Post-install check for binary
141+
if ! [ -x "/usr/bin/php$version" ]; then
142+
phpvm_warn "php$version installed, but /usr/bin/php$version not found. You may need to install php$version-cli or check your PATH."
143+
fi
137144
;;
138145
dnf | yum)
139146
run_with_sudo $PKG_MANAGER install -y php"$version" || {
@@ -166,8 +173,10 @@ get_installed_php_version() {
166173

167174
if command -v php-config >/dev/null 2>&1; then
168175
php-config --version
169-
else
176+
elif command -v php >/dev/null 2>&1; then
170177
php -v | awk '/^PHP/ {print $2}'
178+
else
179+
echo "N/A"
171180
fi
172181
}
173182

@@ -203,21 +212,49 @@ use_php_version() {
203212
brew)
204213
phpvm_debug "Unlinking any existing PHP version..."
205214
brew unlink php >/dev/null 2>&1 || true
206-
brew unlink php@*.* >/dev/null 2>&1 || true
215+
# Unlink all versioned PHP installations
216+
for php_formula in $(brew list --formula | grep -E '^php@[0-9]+\.[0-9]+$'); do
217+
brew unlink "$php_formula" >/dev/null 2>&1 || true
218+
done
207219

208220
if [ "$version" = "system" ]; then
209221
# Special case for switching to system PHP
210222
echo "system" >"$PHPVM_ACTIVE_VERSION_FILE"
211-
phpvm_echo "Switched to system PHP."
212-
return 0
223+
# Remove the current symlink since we're using system PHP
224+
rm -f "$PHPVM_CURRENT_SYMLINK"
225+
226+
# On macOS, "system" PHP typically means the main Homebrew php formula
227+
# since Apple removed PHP from macOS starting with macOS Monterey 12.0
228+
if [ -d "$HOMEBREW_PREFIX/Cellar/php" ]; then
229+
phpvm_debug "Linking Homebrew php formula as system default..."
230+
brew link php --force --overwrite >/dev/null 2>&1 || {
231+
phpvm_err "Failed to link Homebrew php formula."
232+
return 1
233+
}
234+
phpvm_echo "Switched to system PHP (Homebrew default)."
235+
return 0
236+
# Fallback: check for any system PHP in standard locations (rare on modern macOS)
237+
elif command -v php >/dev/null 2>&1; then
238+
phpvm_echo "Switched to system PHP."
239+
return 0
240+
else
241+
phpvm_echo "Switched to system PHP."
242+
phpvm_warn "No system PHP found. You may need to install PHP with 'brew install php' or switch to a specific version."
243+
return 0
244+
fi
213245
fi
214246

215247
if [ -d "$HOMEBREW_PREFIX/Cellar/php@$version" ]; then
216248
phpvm_debug "Linking PHP $version..."
217-
brew link php@"$version" --force --overwrite || {
218-
phpvm_err "Failed to link PHP $version."
249+
link_output=$(brew link php@"$version" --force --overwrite 2>&1)
250+
if echo "$link_output" | grep -iq "Already linked"; then
251+
phpvm_warn "Homebrew reports PHP $version is already linked. To relink, run: brew unlink php@${version} && brew link --force php@${version}"
252+
phpvm_warn "Switch NOT completed. Please relink manually."
219253
return 1
220-
}
254+
elif echo "$link_output" | grep -q "Error"; then
255+
phpvm_err "Failed to link PHP $version: $link_output"
256+
return 1
257+
fi
221258
elif [ -d "$HOMEBREW_PREFIX/Cellar/php" ]; then
222259
installed_version=$(get_installed_php_version)
223260
if [ "$installed_version" = "$version" ]; then
@@ -340,7 +377,7 @@ list_installed_versions() {
340377
fi
341378
fi
342379
done
343-
echo " system (macOS built-in PHP)"
380+
echo " system (Homebrew default PHP)"
344381
echo ""
345382
if [ -f "$PHPVM_ACTIVE_VERSION_FILE" ]; then
346383
active_version=$(cat "$PHPVM_ACTIVE_VERSION_FILE")
@@ -368,10 +405,10 @@ list_installed_versions() {
368405
fi
369406
done
370407
fi
371-
echo " system (macOS built-in PHP)"
408+
echo " system (Homebrew default PHP)"
372409
;;
373410
apt)
374-
dpkg -l | grep -E '^ii +php[0-9]+\.[0-9]+' | awk '{print " " $2}' | sed 's/^ php//'
411+
dpkg-query -W -f='${Package}\n' | grep -E '^php[0-9]+\.[0-9]+' | sed 's/^php//' | awk '{print " "$1}'
375412
echo " system (default system PHP)"
376413
;;
377414
dnf | yum)
@@ -406,6 +443,7 @@ Usage:
406443
phpvm list List installed PHP versions
407444
phpvm help Show this help message
408445
phpvm test Run self-tests to verify functionality
446+
phpvm version Show version information
409447
410448
Examples:
411449
phpvm install 8.1 Install PHP 8.1
@@ -415,6 +453,19 @@ Examples:
415453
EOF
416454
}
417455

456+
# Print version information
457+
print_version() {
458+
cat <<EOF
459+
phpvm version $PHPVM_VERSION
460+
461+
PHP Version Manager for macOS and Linux
462+
Author: Jerome Thayananthajothy <[email protected]>
463+
Repository: https://github.com/Thavarshan/phpvm
464+
465+
Usage: phpvm help
466+
EOF
467+
}
468+
418469
# Self-tests for phpvm functionality
419470
run_tests() {
420471
# Set up test environment
@@ -909,6 +960,9 @@ main() {
909960
help)
910961
print_help
911962
;;
963+
version | --version | -v)
964+
print_version
965+
;;
912966
test)
913967
run_tests
914968
;;

0 commit comments

Comments
 (0)