Skip to content

Commit fb77d09

Browse files
authored
Merge pull request #56 from mlocati/fix-installing-yaml-extension
Fix installing yaml extension on PHP < 7.2
2 parents 64a9860 + 9c5746a commit fb77d09

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

PhpManager/private/PhpVersion.ps1

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,19 @@ class PhpVersionInstalled : PhpVersion
271271
}
272272
$directoryPath = $directory.FullName.TrimEnd($directorySeparator) + $directorySeparator
273273
$actualDirectoryPath = $null
274-
if ($directory.Target -and $directory.Target.Count -gt 0 -and $directory.Target[0]) {
275-
try {
276-
$actualDirectoryPath = (Get-Item -LiteralPath $directory.Target[0]).FullName.TrimEnd($directorySeparator) + $directorySeparator
277-
} catch {
278-
Write-Debug $_
274+
if ($directory.Target) {
275+
$target = $null
276+
if ($directory.Target -is [string]) {
277+
$target = $directory.Target
278+
} elseif ($directory.Target.Count -gt 0) {
279+
$target = $directory.Target[0]
280+
}
281+
if ($target) {
282+
try {
283+
$actualDirectoryPath = (Get-Item -LiteralPath $directory.Target[0]).FullName.TrimEnd($directorySeparator) + $directorySeparator
284+
} catch {
285+
Write-Debug $_
286+
}
279287
}
280288
}
281289
if (-Not($actualDirectoryPath)) {

PhpManager/public/Install-PhpExtension.ps1

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
}
128128
Write-Verbose ("Downloading PECL package {0} {1} from {2}" -f $peclPackageHandle, $availablePackageVersion.PackageVersion, $availablePackageVersion.PackageArchiveUrl)
129129
$downloadedFile, $keepDownloadedFile = Get-FileFromUrlOrCache -Url $availablePackageVersion.PackageArchiveUrl
130+
$additionalFiles = @()
130131
try {
131132
if ($remoteFileIsZip) {
132133
$tempFolder = New-TempDirectory
@@ -142,6 +143,14 @@
142143
throw ("Multiple PHP DLL found in archive downloaded from {0}" -f $availablePackageVersion.PackageArchiveUrl)
143144
}
144145
$dllPath = $phpDlls[0].FullName
146+
switch ($peclPackageHandle) {
147+
'yaml' {
148+
$yamlDll = Join-Path -Path $tempFolder -ChildPath 'yaml.dll'
149+
if (Test-Path -LiteralPath $yamlDll -PathType Leaf) {
150+
$additionalFiles += $yamlDll
151+
}
152+
}
153+
}
145154
}
146155
else {
147156
$keepDownloadedFile = $true
@@ -179,6 +188,15 @@
179188
} catch {
180189
Write-Debug -Message "Failed to reset the ACL for $($oldExtension.Filename): $($_.Exception.Message)"
181190
}
191+
foreach ($additionalFile in $additionalFiles) {
192+
$additionalFileDestination = Join-Path -Path $phpVersion.ActualFolder -ChildPath $(Split-Path -Path $additionalFile -Leaf)
193+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
194+
try {
195+
Reset-Acl -Path $additionalFileDestination
196+
} catch {
197+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
198+
}
199+
}
182200
if ($oldExtension.State -eq $Script:EXTENSIONSTATE_DISABLED -and -Not($DontEnable)) {
183201
Enable-PhpExtension -Extension $oldExtension.Name -Path $phpVersion.ExecutablePath
184202
}
@@ -198,6 +216,15 @@
198216
} catch {
199217
Write-Debug -Message "Failed to reset the ACL for $($newExtensionFilename): $($_.Exception.Message)"
200218
}
219+
foreach ($additionalFile in $additionalFiles) {
220+
$additionalFileDestination = Join-Path -Path $phpVersion.ActualFolder -ChildPath $(Split-Path -Path $additionalFile -Leaf)
221+
Copy-Item -LiteralPath $additionalFile -Destination $additionalFileDestination -Force
222+
try {
223+
Reset-Acl -Path $additionalFileDestination
224+
} catch {
225+
Write-Debug -Message "Failed to reset the ACL for $($additionalFileDestination): $($_.Exception.Message)"
226+
}
227+
}
201228
if (-Not($DontEnable)) {
202229
Write-Verbose "Enabling extension ""$($newExtension.Name)"" for ""$($phpVersion.ExecutablePath)"""
203230
Enable-PhpExtension -Extension $newExtension.Name -Path $phpVersion.ExecutablePath

test/setup.ps1

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ Write-Host " - Windows installation type: $($pcInfo.WindowsInstallationType)"
44
Write-Host " - Windows version name: $($pcInfo.WindowsProductName)"
55
Write-Host " - PowerShell edition: $($PSVersionTable.PSEdition)"
66
Write-Host " - PowerShell version: $($PSVersionTable.PSVersion.ToString())"
7+
try {
8+
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
9+
} catch {
10+
Write-Host 'Failed to configure TLS1.2 for ServicePointManager'
11+
Write-Host $_
12+
}
13+
714
$nuget = Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue
815
if (-Not($nuget)) {
916
Write-Host ' - installing NuGet'

test/tests/Install-Enable-Extensions.Tests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
$imagick.Type | Should -BeExactly 'Php'
5959
$imagick.State | Should -BeExactly 'Disabled'
6060
}
61+
It -Name 'should download and install yaml on PHP <version>' -TestCases $testCases {
62+
param ($path, $version)
63+
Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'yaml' } | Should -HaveCount 0
64+
Install-PhpExtension -Extension yaml -Path $path
65+
$yaml = Get-PhpExtension -Path $path | Where-Object { $_.Handle -eq 'yaml' }
66+
$yaml | Should -HaveCount 1
67+
$yaml.Type | Should -BeExactly 'Php'
68+
$yaml.State | Should -BeExactly 'Enabled'
69+
}
6170
It -Name 'should handle multiple extension versions' {
6271
$phpPath = Join-Path -Path $Global:PHPMANAGER_TESTINSTALLS -ChildPath (New-Guid).Guid
6372
Install-Php -Version 7.1 -Architecture x64 -ThreadSafe $true -Path $phpPath

0 commit comments

Comments
 (0)