-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Install-PhpExtensionPrerequisite.ps1
64 lines (60 loc) · 2.65 KB
/
Install-PhpExtensionPrerequisite.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
57
58
59
60
61
62
63
64
function Install-PhpExtensionPrerequisite() {
<#
.Synopsis
Installs the prerequisites of PHP extensions.
.Parameter Extension
The name (or the handle) of the PHP extension(s) to be disabled.
.Parameter InstallPath
The path to a directory where the prerequisites should be installed (it should be in your PATH environment variable).
If omitted we'll install the dependencies in the PHP directory.
.Parameter PhpPath
The path to the PHP installation.
If omitted we'll use the one found in the PATH environment variable.
.Example
Install-PhpExtensionPrerequisite imagick,zip
#>
[OutputType()]
param (
[Parameter(Mandatory = $true, Position = 0, HelpMessage = 'The name (or the handle) of the PHP extension(s) to be disabled')]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string[]] $Extension,
[Parameter(Mandatory = $false, Position = 1, HelpMessage = 'The path to a directory where the prerequisites should be installed (it should be in your PATH environment variable); if omitted we''ll install the dependencies in the PHP directory')]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string] $InstallPath,
[Parameter(Mandatory = $false, Position = 2, HelpMessage = 'The path to the PHP installation; if omitted we''ll use the one found in the PATH environment variable')]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string] $PhpPath
)
begin {
}
process {
if ($null -eq $PhpPath -or $PhpPath -eq '') {
$phpVersion = [PhpVersionInstalled]::FromEnvironmentOne()
Write-Verbose "Using PHP found in $($phpVersion.ActualFolder)"
} else {
$phpVersion = [PhpVersionInstalled]::FromPath($Path)
}
if ($null -eq $InstallPath -or $InstallPath -eq '') {
$InstallPath = $phpVersion.ActualFolder
} elseif (-not(Test-Path -LiteralPath $InstallPath -PathType Container)) {
throw "The directory $InstallPath does not exist"
}
foreach ($wantedExtension in $Extension) {
$wantedExtensionHandle = Get-PhpExtensionHandle -Name $wantedExtension
Write-Verbose "Checking prerequisites for $wantedExtensionHandle"
switch ($wantedExtensionHandle) {
imagick {
Install-ImagickPrerequisite -PhpVersion $phpVersion -InstallPath $InstallPath
}
default {
Write-Verbose "No prerequisites needed for $wantedExtensionHandle"
}
}
}
}
end {
}
}