-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from mlocati/install-extension-dependencies-ma…
…nually Add Install-PhpExtensionPrerequisites command
- Loading branch information
Showing
6 changed files
with
157 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
function Install-ImagickPrerequisite() { | ||
<# | ||
.Synopsis | ||
Installs the prerequisites for the imagick PHP extension. | ||
.Parameter PhpVersion | ||
The PhpVersion instance the extension will be installed for. | ||
.Parameter InstallPath | ||
The path to a directory where the prerequisites should be installed. | ||
#> | ||
[OutputType()] | ||
param ( | ||
[Parameter(Mandatory = $true, Position = 0)] | ||
[ValidateNotNull()] | ||
[PhpVersionInstalled] $PhpVersion, | ||
[Parameter(Mandatory = $true, Position = 1)] | ||
[ValidateNotNull()] | ||
[ValidateLength(1, [int]::MaxValue)] | ||
[string] $InstallPath | ||
) | ||
begin { | ||
} | ||
process { | ||
$rxSearch = '/ImageMagick-[\d\.\-]+-(VC|vc|vs)' + $PhpVersion.VCVersion + '-' + $PhpVersion.Architecture + '\.zip$' | ||
$pageUrl = 'https://windows.php.net/downloads/pecl/deps/' | ||
Set-NetSecurityProtocolType | ||
$webResponse = Invoke-WebRequest -UseBasicParsing -Uri $pageUrl | ||
$zipUrl = $null | ||
foreach ($link in $webResponse.Links) { | ||
$fullUrl = [Uri]::new([Uri]$pageUrl, $link.Href).AbsoluteUri | ||
if ($fullUrl -match $rxSearch) { | ||
$zipUrl = $fullUrl | ||
break | ||
} | ||
} | ||
if ($null -eq $zipUrl) { | ||
throw ('Unable to find the imagick package dependencies on {0} for {1}' -f $pageUrl, $PhpVersion.DisplayName) | ||
} | ||
Write-Verbose "Downloading and extracting $zipUrl" | ||
$zipFile, $keepZipFile = Get-FileFromUrlOrCache -Url $zipUrl | ||
try { | ||
$tempFolder = New-TempDirectory | ||
try { | ||
try { | ||
Expand-ArchiveWith7Zip -ArchivePath $zipFile -DestinationPath $tempFolder | ||
} catch { | ||
$keepZipFile = $false | ||
throw | ||
} | ||
$items = Get-ChildItem -LiteralPath $tempFolder -Recurse -File -Filter *.dll ` | Where-Object { $_.Name -like 'CORE_RL_*.dll' -or $_.Name -like 'IM_MOD_RL_*.dll' } | ||
foreach ($item in $items) { | ||
$destinationPath = [System.IO.Path]::Combine($InstallPath, $item.Name) | ||
Move-Item -LiteralPath $item.FullName -Destination $destinationPath -Force | ||
try { | ||
Reset-Acl -Path $destinationPath | ||
} catch { | ||
Write-Debug -Message "Failed to reset the ACL for $($destinationPath): $($_.Exception.Message)" | ||
} | ||
} | ||
} finally { | ||
try { | ||
Remove-Item -Path $tempFolder -Recurse -Force | ||
} catch { | ||
Write-Debug 'Failed to remove temporary folder' | ||
} | ||
} | ||
} finally { | ||
if (-Not($keepZipFile)) { | ||
try { | ||
Remove-Item -Path $zipFile | ||
} catch { | ||
Write-Debug 'Failed to remove temporary zip file' | ||
} | ||
} | ||
} | ||
} | ||
end { | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters