Skip to content

Commit 3c654bf

Browse files
committed
Add "Current" PHP version to PHP Switcher
1 parent da27a6d commit 3c654bf

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

PhpManager/private/New-PhpSwitcher.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
$result.Scope = $Data.scope
2121
$result.Alias = $Data.alias
2222
$result.Targets = $Data.targets
23+
$result.Current = ''
24+
if ($Data.ContainsKey('current') -and ($null -ne $Data.current)) {
25+
$result.Current = $Data.current
26+
}
2327
}
2428
end {
2529
$result

PhpManager/private/PhpSwitcher.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@
2121
[hashtable]
2222
[ValidateNotNull()]
2323
$Targets
24+
<#
25+
The name of the currently activated version (empty string if none)
26+
#>
27+
[string]
28+
[ValidateNotNull()]
29+
$Current
2430
}

PhpManager/public/Get-PhpSwitcher.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,23 @@
2929
}
3030
}
3131
if ($data.alias -ne '') {
32+
$currentTarget = $null
33+
if (Test-Path -LiteralPath $data.alias -PathType Container) {
34+
$aliasItem = Get-Item -LiteralPath $data.alias
35+
if ($aliasItem.LinkType -eq 'Junction') {
36+
$currentTarget = $aliasItem.Target
37+
}
38+
}
3239
$data.targets = @{}
3340
if ($definition | Get-Member -Name 'Targets') {
3441
try {
3542
$definition.Targets.PSObject.Properties | ForEach-Object {
3643
$data.targets[$_.Name] = [string] $_.Value
44+
if ($null -ne $currentTarget) {
45+
if ($_.Value -eq $currentTarget) {
46+
$data.current = $_.Name
47+
}
48+
}
3749
}
3850
} catch {
3951
Write-Debug $_.Exception.Message

0 commit comments

Comments
 (0)