@@ -214,11 +214,11 @@ function Write-UsageLine ([string]$CommandText, [string]$Description) {
214214
215215function Show-Help {
216216 Write-Host " "
217- Write-Host " ____ __ __ " - ForegroundColor Cyan
218- Write-Host " / __ \/ /_ ____ _/ /_" - ForegroundColor Cyan
219- Write-Host " / /_/ / __ \/ __ `/ __/" - ForegroundColor Cyan
220- Write-Host " / ____/ / / / /_/ / /_ " - ForegroundColor Cyan
221- Write-Host " /_/ /_/ /_/\__,_/\__/ " - ForegroundColor Cyan
217+ Write-Host " ____ __ __ " - ForegroundColor Cyan
218+ Write-Host " / __ \/ /_ ____ _/ /_ " - ForegroundColor Cyan
219+ Write-Host " / /_/ / __ \/ __ `/ __/ " - ForegroundColor Cyan
220+ Write-Host " / ____/ / / / /_/ / /_ " - ForegroundColor Cyan
221+ Write-Host " /_/ /_/ /_/\__,_/\__/ " - ForegroundColor Cyan
222222 Write-Host " "
223223 Write-Host " Phat - My Personal XAMPP PHP Version Switcher " - ForegroundColor Gray
224224 Write-Host " Github: @pphatdev" - ForegroundColor Gray
@@ -232,12 +232,14 @@ function Show-Help {
232232 Write-UsageLine " phat switch [version]" " -> Switch to a PHP version"
233233 Write-UsageLine " phat use [version]" " -> Alias for switch"
234234 Write-UsageLine " phat install [version]" " -> Download and install a PHP version"
235+ Write-UsageLine " phat uninstall [version]" " -> Remove an installed PHP version"
235236 Write-UsageLine " phat help" " -> Show this help"
236237 Write-Host " "
237238 Write-Host " Examples:"
238239 Write-ExampleLine " phat list --php --global"
239240 Write-ExampleLine " phat switch 7.4.33"
240241 Write-ExampleLine " phat install 8.2.27"
242+ Write-ExampleLine " phat uninstall 7.4.33"
241243 Write-Host " "
242244}
243245
@@ -530,6 +532,67 @@ function Invoke-Install ([string]$Version) {
530532 Write-Host " "
531533}
532534
535+ function Invoke-Uninstall ([string ]$Version ) {
536+ if (-not $Version ) {
537+ Write-Host " Error: Version required. Usage: phat uninstall [version]" - ForegroundColor Red
538+ Write-Host " Example: phat uninstall 8.2.27" - ForegroundColor Gray
539+ return
540+ }
541+
542+ $targetDir = Join-Path $XAMPP_ROOT " php$Version "
543+ $currentDir = Join-Path $XAMPP_ROOT " php"
544+
545+ # Validate target exists
546+ if (-not (Test-Path $targetDir )) {
547+ Write-Host " Error: php$Version is not installed in $XAMPP_ROOT " - ForegroundColor Red
548+ Write-Host " Available:" - ForegroundColor Gray
549+ Get-ChildItem - Path $XAMPP_ROOT - Directory - Filter " php*" |
550+ Where-Object { $_.Name -ne " php" -and $_.Name -ne " phpMyAdmin" } |
551+ ForEach-Object { Write-Host " $ ( $_.Name -replace ' ^php' , ' ' ) " }
552+ return
553+ }
554+
555+ # Check if trying to uninstall the active version
556+ $currentVer = Get-PhpVersion $currentDir
557+ $targetVer = Get-PhpVersion $targetDir
558+
559+ if ($currentVer -and $targetVer -and ($currentVer -eq $targetVer )) {
560+ Write-Host " Error: Cannot uninstall the currently active PHP version ($Version )" - ForegroundColor Red
561+ Write-Host " Please switch to another version first." - ForegroundColor Yellow
562+ return
563+ }
564+
565+ Write-Host " "
566+ Write-Host " Uninstalling PHP $Version ..." - ForegroundColor Cyan
567+ Write-Host " "
568+
569+ # Confirmation prompt
570+ Write-Host " This will permanently delete: $targetDir " - ForegroundColor Yellow
571+ $confirmation = Read-Host " Type 'yes' to confirm"
572+
573+ if ($confirmation -ne ' yes' ) {
574+ Write-Host " "
575+ Write-Host " Uninstall cancelled." - ForegroundColor Gray
576+ Write-Host " "
577+ return
578+ }
579+
580+ # Remove the directory
581+ try {
582+ Write-Host " "
583+ Write-Host " Removing PHP $Version ..." - ForegroundColor White
584+ Remove-Item - Path $targetDir - Recurse - Force - ErrorAction Stop
585+ Write-Host " "
586+ Write-Host " Done! PHP $Version has been uninstalled." - ForegroundColor Green
587+ Write-Host " "
588+ }
589+ catch {
590+ Write-Host " "
591+ Write-Host " Error: Failed to remove PHP $Version - $_ " - ForegroundColor Red
592+ Write-Host " "
593+ }
594+ }
595+
533596# ── Dispatch ───────────────────────────────────────────────────────────────────
534597
535598if ($VersionFlag ) {
@@ -543,6 +606,7 @@ switch ($Command) {
543606 " switch" { Invoke-Switch $Argument }
544607 " use" { Invoke-Switch $Argument }
545608 " install" { Invoke-Install $Argument }
609+ " uninstall" { Invoke-Uninstall $Argument }
546610 " help" { Show-Help }
547611
548612 default { Show-Help }
0 commit comments