Skip to content

Commit

Permalink
Add "Current" PHP version to PHP Switcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mlocati committed Oct 2, 2019
1 parent da27a6d commit 3c654bf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions PhpManager/private/New-PhpSwitcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
$result.Scope = $Data.scope
$result.Alias = $Data.alias
$result.Targets = $Data.targets
$result.Current = ''
if ($Data.ContainsKey('current') -and ($null -ne $Data.current)) {
$result.Current = $Data.current
}
}
end {
$result
Expand Down
6 changes: 6 additions & 0 deletions PhpManager/private/PhpSwitcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@
[hashtable]
[ValidateNotNull()]
$Targets
<#
The name of the currently activated version (empty string if none)
#>
[string]
[ValidateNotNull()]
$Current
}
12 changes: 12 additions & 0 deletions PhpManager/public/Get-PhpSwitcher.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,23 @@
}
}
if ($data.alias -ne '') {
$currentTarget = $null
if (Test-Path -LiteralPath $data.alias -PathType Container) {
$aliasItem = Get-Item -LiteralPath $data.alias
if ($aliasItem.LinkType -eq 'Junction') {
$currentTarget = $aliasItem.Target
}
}
$data.targets = @{}
if ($definition | Get-Member -Name 'Targets') {
try {
$definition.Targets.PSObject.Properties | ForEach-Object {
$data.targets[$_.Name] = [string] $_.Value
if ($null -ne $currentTarget) {
if ($_.Value -eq $currentTarget) {
$data.current = $_.Name
}
}
}
} catch {
Write-Debug $_.Exception.Message
Expand Down

0 comments on commit 3c654bf

Please sign in to comment.