-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSet-PhpenvVersion.ps1
56 lines (45 loc) · 1.41 KB
/
Set-PhpenvVersion.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<#
.SYNOPSIS
Set either current local or current global php version depending on parameter -Local or -Global.
.DESCRIPTION
None
.PARAMETER Global
Whenever to set global php version.
.PARAMETER Local
Whenever to set local php version.
.PARAMETER Version
The specific php version to set.
.NOTES
None
.INPUTS
None
.OUTPUTS
Error if specified version is not installed.
#>
function Set-PhpenvVersion
{
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, Position=0, ParameterSetName = "global")]
[switch]$Global = $False,
[Parameter(Mandatory = $true, Position=0, ParameterSetName = "local")]
[switch]$Local = $False,
[Parameter(Mandatory = $true, Position=1)]
[version]$Version
)
Write-FunctionCallLogMessage -Invocation $MyInvocation -Parameters $PSBoundParameters
Write-Verbose "Setting local version to $($Version)"
$versions = List-PhpenvVersions
if (-Not $null -ne ($versions | ? { $Version -match $_ })) {
Write-Error "Version $($Version) is not installed."
return
}
if ($Local) {
Write-Verbose "Writing $($Version) to $(Get-PhpenvDefaultLocalVersionFile)"
"$($Version)" | Set-Content (Get-PhpenvDefaultLocalVersionFile)
}
if ($Global) {
Write-Verbose "Writing $($Version) to $(Get-PhpenvDefaultGlobalVersionFile)"
"$($Version)" | Set-Content (Get-PhpenvDefaultGlobalVersionFile)
}
}