Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion linux/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

set -e

PHPVM_VERSION="1.8.1"
PHPVM_VERSION="1.8.2"
PHPVM_DIR="${PHPVM_DIR:-$HOME/.phpvm}"
PHPVM_REPO="https://raw.githubusercontent.com/devhardiyanto/phpvm/main"

Expand Down
2 changes: 1 addition & 1 deletion linux/phpvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# phpvm use 8.3.0
# ==============================================================================

PHPVM_VERSION="1.8.1"
PHPVM_VERSION="1.8.2"
PHPVM_DIR="${PHPVM_DIR:-$HOME/.phpvm}"
PHPVM_VERSIONS="$PHPVM_DIR/versions"
PHPVM_CURRENT="$PHPVM_DIR/current"
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.8.1
1.8.2
23 changes: 22 additions & 1 deletion windows/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,34 @@
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

$PHPVM_VERSION = "1.8.1"
$PHPVM_VERSION = "1.8.2"
$PHPVM_DIR = if ($env:PHPVM_DIR) { $env:PHPVM_DIR } else { "$env:USERPROFILE\.phpvm" }
$PHPVM_BIN = "$PHPVM_DIR\bin"

function Write-Ok ($m) { Write-Host " $m" -ForegroundColor Green }
function Write-Step ($m) { Write-Host " > $m" -ForegroundColor Cyan }
function Write-Warn ($m) { Write-Host " [warn] $m" -ForegroundColor Yellow }

# Broadcast WM_SETTINGCHANGE so new terminals pick up the PATH without a logout.
function Send-EnvChangeBroadcast {
if (-not ("PHPVM.NativeMethods" -as [type])) {
try {
Add-Type -Namespace PHPVM -Name NativeMethods -MemberDefinition @'
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern System.IntPtr SendMessageTimeout(
System.IntPtr hWnd, uint Msg, System.IntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out System.UIntPtr lpdwResult);
'@
} catch { return }
}
$out = [System.UIntPtr]::Zero
try {
[void][PHPVM.NativeMethods]::SendMessageTimeout(
[System.IntPtr]0xffff, 0x1A, [System.IntPtr]::Zero,
"Environment", 0x2, 5000, [ref]$out)
} catch { $null = $_ }
}

Write-Host ""
Write-Host " phpvm $PHPVM_VERSION - PHP Version Manager for Windows" -ForegroundColor Cyan
Write-Host " ------------------------------------------------------" -ForegroundColor DarkGray
Expand Down Expand Up @@ -60,6 +80,7 @@ if ($null -eq $userPath) { $userPath = "" }
if ($userPath -notlike "*$PHPVM_BIN*") {
$newPath = "$PHPVM_BIN;$userPath" -replace ";{2,}", ";"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Send-EnvChangeBroadcast
Write-Ok "Added to user PATH -> $PHPVM_BIN"
} else {
Write-Warn "$PHPVM_BIN already in PATH, skipping."
Expand Down
34 changes: 31 additions & 3 deletions windows/phpvm.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"

# -- Constants -----------------------------------------------------------------
$PHPVM_VERSION = "1.8.1"
$PHPVM_VERSION = "1.8.2"
$PHPVM_DIR = if ($env:PHPVM_DIR) { $env:PHPVM_DIR } else { "$env:USERPROFILE\.phpvm" }
$VERSIONS_DIR = "$PHPVM_DIR\versions"
$CURRENT_LINK = "$PHPVM_DIR\current"
Expand Down Expand Up @@ -65,6 +65,31 @@ function Write-Step ($m) { Write-Host " > $m" -ForegroundColor Cyan }
function Write-Warn ($m) { Write-Host " [warn] $m" -ForegroundColor Yellow }
function Write-Dim ($m) { Write-Host " $m" -ForegroundColor DarkGray }

# Broadcast WM_SETTINGCHANGE so running processes (Explorer, and the terminals
# it spawns afterward) refresh their environment block after a User PATH change,
# instead of needing a logout. Best-effort; any failure is swallowed.
function Send-EnvChangeBroadcast {
if (-not ("PHPVM.NativeMethods" -as [type])) {
try {
Add-Type -Namespace PHPVM -Name NativeMethods -MemberDefinition @'
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern System.IntPtr SendMessageTimeout(
System.IntPtr hWnd, uint Msg, System.IntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out System.UIntPtr lpdwResult);
'@
} catch { return }
}
$HWND_BROADCAST = [System.IntPtr]0xffff
$WM_SETTINGCHANGE = 0x1A
$SMTO_ABORTIFHUNG = 0x2
$out = [System.UIntPtr]::Zero
try {
[void][PHPVM.NativeMethods]::SendMessageTimeout(
$HWND_BROADCAST, $WM_SETTINGCHANGE, [System.IntPtr]::Zero,
"Environment", $SMTO_ABORTIFHUNG, 5000, [ref]$out)
} catch { $null = $_ }
}

# -- Init ----------------------------------------------------------------------
function Initialize-PHPVM {
# GitHub blocks TLS < 1.2
Expand Down Expand Up @@ -402,14 +427,17 @@ function Invoke-Use ([string]$ver) {
$newPath = (@($CURRENT_LINK) + $parts -join ";") -replace ";{2,}", ";"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
if ($env:PATH -notlike "*$CURRENT_LINK*") { $env:PATH = "$CURRENT_LINK;$env:PATH" }
# Propagate the PATH change to the rest of the system so new terminals get it
# without a logout. This session was already updated on the line above.
Send-EnvChangeBroadcast

Write-Ok "Now using PHP $ver"
try {
& "$CURRENT_LINK\php.exe" --version 2>$null
& "$CURRENT_LINK\php.exe" --version 2>$null | ForEach-Object { Write-Host " $_" }
} catch {
return
}
Write-Warn "Restart your terminal if 'php -v' still shows the previous version."
Write-Dim "Active in this terminal now. Other already-open terminals pick it up when reopened."
}

function Invoke-List {
Expand Down
22 changes: 22 additions & 0 deletions windows/uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ function Write-Warn ($m) { Write-Host " [warn] $m" -ForegroundColor Yellow }
function Write-Err ($m) { Write-Host " [error] $m" -ForegroundColor Red }
function Write-Dim ($m) { Write-Host " $m" -ForegroundColor DarkGray }

# Broadcast WM_SETTINGCHANGE so running processes drop the removed PATH entry
# without a logout. Best-effort.
function Send-EnvChangeBroadcast {
if (-not ("PHPVM.NativeMethods" -as [type])) {
try {
Add-Type -Namespace PHPVM -Name NativeMethods -MemberDefinition @'
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern System.IntPtr SendMessageTimeout(
System.IntPtr hWnd, uint Msg, System.IntPtr wParam, string lParam,
uint fuFlags, uint uTimeout, out System.UIntPtr lpdwResult);
'@
} catch { return }
}
$out = [System.UIntPtr]::Zero
try {
[void][PHPVM.NativeMethods]::SendMessageTimeout(
[System.IntPtr]0xffff, 0x1A, [System.IntPtr]::Zero,
"Environment", 0x2, 5000, [ref]$out)
} catch { $null = $_ }
}

if ($Help) {
Write-Host ""
Write-Host " phpvm uninstaller"
Expand Down Expand Up @@ -79,6 +100,7 @@ $parts = $userPath -split ";" | Where-Object {
$newPath = ($parts -join ";") -replace ";{2,}", ";"
if ($newPath -ne $userPath) {
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
Send-EnvChangeBroadcast
Write-Ok "Removed phpvm from User PATH."
} else {
Write-Dim "No phpvm entry found in User PATH."
Expand Down